[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] How do I set up a counter or sequence number variable


Subject: [xsl] How do I set up a counter or sequence number variable
From: "Catherine Wilbur cwilbur@xxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 3 Nov 2014 19:48:24 -0000

Looked on the archive and did not see anything similar to what I am doing. 
 I am trying to put a sequence number for each output line.  Each time I 
output a line I want to increment the counter by one.  Noticed on internet 
once you change a variable in XSLT you cannot change the value.  How do I 
set up a sequence number.  This is how my output is coming out.

1, PO-305, USD, 22, ABE, 2014082450002181, ACCOUNTINGDEPARTMENT, 1.0742, 
20, 18105.8820, 201411031316LUSD, 0, 20140724, 20141103
1, PO-305, USD, 22, ABE, 2014082450002181, ACCOUNTINGDEPARTMENT, 1.0742, 
2, 18105.8430, 201411031316LUSD, 0, 20140724, 20141103

Want the output to come out as follows (first field is my sequence number)

1, PO-305, USD, 22, ABE, 2014082450002181, ACCOUNTINGDEPARTMENT, 1.0742, 
20, 18105.8820, 201411031316LUSD, 0, 20140724, 20141103
2, PO-305, USD, 22, ABE, 2014082450002181, ACCOUNTINGDEPARTMENT, 1.0742, 
2, 18105.8430, 201411031316LUSD, 0, 20140724, 20141103


Here is my XSLT code

<?xml version="1.0" encoding="UTF-8" ?>

<!-- New document created with EditiX at Thu Oct 23 16:28:34 EDT 2014 -->

<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"
        xmlns:date="http://exslt.org/dates-and-times"
        extension-element-prefixes="date">


        <xsl:output method="text" indent="no"/>
 
        <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]')"/>
 
 
        <!-- OUSTANDING OUTPUT DATA ISSUES -->
        <!-- xsl:value-of select="../../../../../hardcode_RemarkString" 
/>, derived field --> 
        <!-- xsl:value-of select="../../../../../hardcode_PayTerms" />, 
derived from part of invoice/invoice_number --> 
        <!-- xsl:value-of select="../../../../../hardcode_Attachments" />, 
derived from part of invoice/invoice_number --> 
 
         <xsl:template name="iterate">
                 <xsl:param name="length" select="5"/>
                 <xsl:param name="i" select="1"/>
                 <pos><xsl:value-of select="$i"/></pos>
                 <xsl:if test="$length > 1">
                                <xsl:call-template name="iterate">
                                        <xsl:with-param name="length" 
select="$length - 1"/>
                                        <xsl:with-param name="i" 
select="$i + 1"/>
                                </xsl:call-template>
                        </xsl:if>
        </xsl:template>
 
        <xsl:template match="/">
                <xsl:for-each 
select="payment_data/invoice_list/invoice/invoice_line_list/invoice_line/fund_info_list/fund_info/amount">
                        <xsl:variable name="inv" select="../../../../.."/>
                        <xsl:variable name="InvoiceDateValue" 
select="translate(../../../../../invoice_date,'/','')"/>
                        <xsl:variable name="InvoiceVendorNo" 
select="../../../../../vendor_FinancialSys_Code"/>
                        <xsl:variable name="InvoiceDateYYYYMMDD" 
select="concat(substring($InvoiceDateValue,5,4),substring($InvoiceDateValue,1,2),substring($InvoiceDateValue,3,2))"/>
                        <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="FISVendorNo">
                                 <xsl:choose>
                                        <xsl:when 
test="string-length($InvoiceVendorNo)!=0">
                                                <xsl:value-of 
select="number($InvoiceVendorNo)"/>
                                        </xsl:when>
                                        <xsl:otherwise>0</xsl:otherwise>
                                </xsl:choose>
                        </xsl:variable> 
 
                        <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>
 
                        <xsl:variable name="LibrBatchNo" 
select="concat($CurrDateTimeValue,$ POOwnerType,$InvoiceCurrency)"/> 
 
                        <xsl:variable name="inv" select="../../../../.."/>
                           <xsl:value-of select="count(sum),
 $inv/(invoice_number,
 invoice_amount/currency, 
 invoice_amount/sum, 
                                                        vendor_code, 
                                                        unique_identifier, 

 payment_method, 
 invoice_exchange_rate_list/exchange_rate/rate), 
                                                                sum,
 ../external_id, 
 $LibrBatchNo,
 $FISVendorNo,
 $InvoiceDateYYYYMMDD,
 $GLDateValue" separator=", "/> 
                                        <xsl:text>&#xa;</xsl:text> 
                  </xsl:for-each> 

        </xsl:template>
</xsl:stylesheet>

_____________________________________________________________________
Catherine Wilbur  |  Senior Application Programmer  |  IT Services
401 Sunset Avenue, Windsor ON Canada  N9B 3P4
(T) 519.253.3000 Ext. 2745  |  (F) 519.973.7083  |  (E) 
cwilbur@xxxxxxxxxxx
www.uwindsor.ca/its


Current Thread
Keywords