nbingen
asked on
xsl:for-each iterate based on count of nodes
I'm new to xsl and need some help.
1. I'm trying to output the same text information based on the count of the node (./shipTo/item/qty)
2. Here's my code. Notice I'm using a variable "numValues" to store the count, so I can use it in my for each. When I do so, I get the error "Cannot convert #NUMBER to a NodeList!"
<xsl:variable name="numValues">
<xsl:value-of select="count(./shipTo/ite m/qty)+1"/ >
</xsl:variable>
<xsl:for-each select="$numValues">
<xsl:value-of select="./transSetId"/>,<x sl:value-o f select="./releaseId"/>,<xs l:value-of select="./shipTo/item/qty" />,<xsl:va lue-of select="./shipTo/item/qty/ @um"/>,<xs l:value-of select="./shipTo/item/qty/ @due"/>,<x sl:text>
</xsl:text>
</xsl:for-each>
3. Here's a sample of what I expect as a result:
830,1234,100,EA,03/11/03
830,1234,200,EA,03/12/03
830,1234,300,EA,03/13/03
830,5678,100,EA,03/11/03
830,5678,200,EA,03/12/03
4. How can I repeat the information for each incident of the ./shipTo/item/qty node?
Can you help?
Thanks.
1. I'm trying to output the same text information based on the count of the node (./shipTo/item/qty)
2. Here's my code. Notice I'm using a variable "numValues" to store the count, so I can use it in my for each. When I do so, I get the error "Cannot convert #NUMBER to a NodeList!"
<xsl:variable name="numValues">
<xsl:value-of select="count(./shipTo/ite
</xsl:variable>
<xsl:for-each select="$numValues">
<xsl:value-of select="./transSetId"/>,<x
</xsl:text>
</xsl:for-each>
3. Here's a sample of what I expect as a result:
830,1234,100,EA,03/11/03
830,1234,200,EA,03/12/03
830,1234,300,EA,03/13/03
830,5678,100,EA,03/11/03
830,5678,200,EA,03/12/03
4. How can I repeat the information for each incident of the ./shipTo/item/qty node?
Can you help?
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks! position() did it. Also used ancestor:: to take care of elements further up in the tree.
In your case, use :
<xsl:for-each select="./shipTo/item/qty"
</xsl:for-each>