[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
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.



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

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

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

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


> I have an xml file like (there can be any number of <tx> elements)
> <payment>
> </payment>
> which I need to group in sets of 3 so that I can output a checksum line
> three lines of the <amt> tags. I also need to do this for the last line as
> 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


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.
First Name
Last Name
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.