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

position() in sequences in XSLT 2.0

Subject: position() in sequences in XSLT 2.0
From: ben.pickering@xxxxxxxxxxxxxxxx
Date: Thu, 15 Jul 2004 10:00:53 +0100
xsl position

I have a document looking like the following, which I'm using to 
generate/populate a web form. 

        <e task="1000">
            <text>Task One Thousand</text>

        <e task="2000">
            <text>Task Two Thousand</text>

        <e task="3000">
            <text>Task Three Thousand</text>

I also want to generate a few empty ones at the end to be filled in by the 
user.  So I'm doing the following with a temporary tree variable which 
matches the structure of the input:

    <xsl:variable name="empty">
          <e task="">

    <xsl:template match="/">
        <xsl:apply-templates select="entries/e, for $d in (1 to 3) return 

    <xsl:template match="e">
       entry <xsl:value-of select="position()"/> of <xsl:value-of 
select="last()"/><br />
       <!-- ...plus the form output, not important -->

And the result I'm getting is

entry 1 of 6
entry 2 of 6
entry 3 of 6
entry 1 of 1
entry 1 of 1
entry 1 of 1

Whereas I was expecting "1 of 6" up to "6 of 6".  So it looks right for 
the first ones, but then seems to go wrong...  I was under the impression 
that position() is the offset into the sequence and that last() is the 
overall size.  Is this wrong?

I notice that if I swap the template for / with

    <xsl:template match="/">
        <xsl:variable name="temp">
           <xsl:copy-of select="entries/e, for $d in (1 to 3) return 
        <xsl:apply-templates select="$temp"/>

Then it works fine.   I'm sort of satisfied to do it this way, but I'd 
like to check I have my facts straight as regards sequences in XSLT 2.0.


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.