xsl-list
[Top] [All Lists]

[xsl] Have a node that appears under each line item. - How do I just pick the first occurance

2014-11-04 14:09:49
Have a variable I define as follows in my code,   How do I pick just the 
first occurance of po_line_owner.  If the invoice has multiple lines with 
each having a po_line_info/po_line_owner I only one to pick up the first 
occurance of  ../../../../invoice_line/po_line_info/po_line_owner 
encountered?
        <xsl:variable name="InvoicePOLineOwner" 
select="../../../../invoice_line/po_line_info/po_line_owner"/>

I then take this variable and perform logic in my code to set the 
following work variable.  I only want to set this variable if I have 
selected the first occurance of po_line_owner how would I do this?  Pulled 
this logic from my code.

                                         <!-- Based on value of 
InvoicePOLineOwner flag the batch as a Leddy batch or a Law batch:  -->    
 
                        <xsl:variable name="POOwnerType">
                                 <xsl:choose>
                                        <xsl:when 
test="contains($InvoicePOLineOwner, 'Law') or 
contains($InvoicePOLineOwner, 'LAW')">
                                                <xsl:value-of 
select="'W'"/>
                                        </xsl:when>
                                        <xsl:otherwise>
                                                <xsl:value-of 
select="'L'"/>
                                        </xsl:otherwise>
                                </xsl:choose>
                        </xsl:variable>


Here is my XSL code

<xsl:stylesheet version="2.0" 
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
        xmlns:xs="http://www.w3.org/2001/XMLSchema";
        xmlns:fn="http://www.w3.org/2005/xpath-functions";
        xmlns:xdt="http://www.w3.org/2005/xpath-datatypes";
        xmlns:err="http://www.w3.org/2005/xqt-errors";
        exclude-result-prefixes="xs xdt err fn"


        <xsl:output method="text" indent="no"/>
 
        <!-- Define two date variables - one for current date and one for 
current date and time:  --> 
        <xsl:variable name="GLDateValue" 
select="format-date(current-date(),'[Y0001][M01][D01]')"/>
        <xsl:variable name="CurrDateTimeValue" 
select="format-dateTime(current-dateTime(),'[Y0001][M01][D01][H01][m01]')"/>
 

        <xsl:template match="/">
                <!-- Loop thru each of the fund_info/amount and write out 
a CSV record for each fund_info entry found:  --> 
                <xsl:for-each 
select="payment_data/invoice_list/invoice/invoice_line_list/invoice_line/fund_info_list/fund_info/amount">
                        <!-- Set the a select string variable to move up 
specified levels (4) then use this string:  --> 
                        <xsl:variable name="inv" select="../../../../.."/>

                                        <!-- Define some work variables 
and initialize the value:  --> 
                        <xsl:variable name="InvoiceDateValue" 
select="translate($inv/invoice_date,'/','')"/>
                        <xsl:variable name="InvoiceVendorCode" 
select="$inv/vendor_code"/>
                        <xsl:variable name="InvoiceVendorNo" 
select="$inv/vendor_FinancialSys_Code"/>
                        <xsl:variable name="InvoiceCurrency" 
select="$inv/invoice_amount/currency"/>
                        <xsl:variable name="InvoicePOLineOwner" 
select="../../../../invoice_line/po_line_info/po_line_owner"/>
                        <xsl:variable name="InvoiceNumber" 
select="$inv/invoice_number"/>
 
                                        <!-- Set FISVendorNo variable to 
the Vendor_FinancialSys_Code or to 99999 if the value is nil:  -->        
                        <xsl:variable name="FISVendorNo">
                                 <xsl:choose>
                                        <xsl:when 
test="string-length($InvoiceVendorNo)!=0">
                                                <xsl:value-of 
select="number($InvoiceVendorNo)"/>
                                        </xsl:when>
 <xsl:otherwise>99999</xsl:otherwise>
                                </xsl:choose>
                        </xsl:variable> 
 
                                        <!-- Set the Payment Attachment 
variable to Attachment or blank based on finding certain strings in 
InvoiceNumber:  -->  
                        <xsl:variable name="PaymentAttachment">
                                 <xsl:choose>
                                        <xsl:when 
test="contains($InvoiceNumber, '(ATC)') or starts-with($InvoiceNumber, 
'PPD')">
                                                <xsl:value-of 
select="'A'"/>
                                        </xsl:when>
                                        <xsl:otherwise>
                                                <xsl:value-of select="' 
'"/>
                                        </xsl:otherwise>
                                </xsl:choose>
                        </xsl:variable>
 
                                        <!-- Set the Payment Terms 
variable to Urgent or blank based on finding certain strings in 
InvoiceNumber or finding certain strings in InvoiceVendorCode:  -->  
                        <xsl:variable name="PaymentTerms">
                                 <xsl:choose>
                                        <xsl:when 
test="contains($InvoiceNumber, '(PPD)') or contains($InvoiceNumber, 
'(RSH)') or starts-with($InvoiceNumber, 'CM') or 
contains($InvoiceVendorCode, 'OCL C')">
                                                <xsl:value-of 
select="'U'"/>
                                        </xsl:when>
                                        <xsl:otherwise>
                                                <xsl:value-of select="' 
'"/>
                                        </xsl:otherwise>
                                </xsl:choose>
                        </xsl:variable>
 
                                         <!-- Based on value of 
InvoicePOLineOwner flag the batch as a Leddy batch or a Law batch:  -->    
 
                        <xsl:variable name="POOwnerType">
                                 <xsl:choose>
                                        <xsl:when 
test="contains($InvoicePOLineOwner, 'Law') or 
contains($InvoicePOLineOwner, 'LAW')">
                                                <xsl:value-of 
select="'W'"/>
                                        </xsl:when>
                                        <xsl:otherwise>
                                                <xsl:value-of 
select="'L'"/>
                                        </xsl:otherwise>
                                </xsl:choose>
                        </xsl:variable>
 
                                         <!-- output the CSV comma 
delimited file with fields in the following order:  -->
                                         <!-- SeqNo, UserId, BatchNo, 
AddrNo, GLAcct, InvoiceNo, InvoiceDate, GLDate, CurrencyCode, 
ExchangeRate, TotalInvoiceAmount, LineItemAmount, Attachment, 
PaymentTerms, Remark -->
                                         <!-- Last field is a new line -->
                                          <xsl:value-of 
select="position(), 
                                'LIBPROD',
                                concat($CurrDateTimeValue,$ 
POOwnerType,$InvoiceCurrency),
                                $FISVendorNo,
                                ../external_id, 
                                $inv/invoice_number,   
 
concat(substring($InvoiceDateValue,5,4),substring($InvoiceDateValue,1,2),substring($InvoiceDateValue,3,2)),
                                $GLDateValue,
                                $inv/invoice_amount/currency,
 $inv/invoice_exchange_rate_list/exchange_rate/rate,
                                $inv/invoice_amount/sum,
                                sum,
                                $PaymentAttachment,
                                $PaymentTerms,
 concat($inv/vendor_code,'/',$inv/unique_identifier) " separator=", "/> 
                                        <xsl:text>&#xa;</xsl:text> 
                         </xsl:for-each> 

        </xsl:template>
</xsl:stylesheet>
_____________________________________________________________________
Catherine Wilbur 
cwilbur(_at_)uwindsor(_dot_)ca
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--
<Prev in Thread] Current Thread [Next in Thread>
  • [xsl] Have a node that appears under each line item. - How do I just pick the first occurance, Catherine Wilbur cwilbur(_at_)uwindsor(_dot_)ca <=