[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: How to select a numbered group of elements

Subject: Re: How to select a numbered group of elements
From: "Joerg Heinicke" <joerg.heinicke@xxxxxx>
Date: Tue, 19 Feb 2002 21:26:12 +0100
paymentid
Hi Philip,

Carmelo gave the right advise. With position() mod 3 you select every third
tx, so you now where to do the sums. Before you have to print every tx,
which happens in the template matching tx without mode.

Regards,

Joerg

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="payment">
    <table border="1">
        <xsl:apply-templates select="tx[position() mod 3 = 1]"
mode="checksum"/>
    </table>
</xsl:template>

<xsl:template match="tx" mode="checksum">
    <xsl:variable name="tx" select=" . | following-sibling::tx[position()
&lt; 3]"/>
    <xsl:apply-templates select="$tx"/>
    <tr>
        <td colspan="2">Checksum: </td>
        <td><xsl:value-of select="sum($tx/amt)"/></td>
    </tr>
</xsl:template>

<xsl:template match="tx">
    <tr>
        <td><xsl:value-of select="paymentId"/></td>
        <td><xsl:value-of select="payType"/></td>
        <td><xsl:value-of select="amt"/></td>
    </tr>
</xsl:template>

</xsl:stylesheet>


> I have an xml file like (there can be any number of <tx> elements)
>
> <payment>
>
<tx><paymentId>123456</paymentId><payType>EURO</payType><amt>10.00</amt></tx
>
>
<tx><paymentId>123457</paymentId><payType>EURO</payType><amt>20.00</amt></tx
>
>
<tx><paymentId>123458</paymentId><payType>EURO</payType><amt>30.00</amt></tx
>
>
<tx><paymentId>123459</paymentId><payType>EURO</payType><amt>40.00</amt></tx
>
>
<tx><paymentId>123460</paymentId><payType>EURO</payType><amt>50.00</amt></tx
>
> </payment>
>
> which I need to group in sets of 3 so that I can output a checksum line
every
> three lines of the <amt> tags. I also need to do this for the last line as
well
>
> eg
> Header Text
> 123456    EURO 10.00
> 123457    EURO 20.00
> 123458    EURO 30.00
> Checksum  60.00
> 123459    EURO 40.00
> 123460 EURO    50.00
> Checksum  90.00
> Footer text
>
> Is this possible with XSLT


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.