A Simple Counter
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 8
- Joined: Tue Oct 02, 2012 4:53 am
A Simple Counter
I'm from a procedural programming background, so I thought by declaring a variable and adding that variable count to +1 would get the running counter.
But it doesnt seem to work.
I also tried
<xsl:variable name="context" select="."/>
<xsl:for each select"/env:Xyx/env.Body/zbcf//fdf">
<xsl:value-of select"$context"/>
</xsl:for-each?
the above variable context displays all values from the node instead of just counter. Isnt there anything simple like X= 1 ; For look X=X+1
display X.
Thanks'
Ash
But it doesnt seem to work.
I also tried
<xsl:variable name="context" select="."/>
<xsl:for each select"/env:Xyx/env.Body/zbcf//fdf">
<xsl:value-of select"$context"/>
</xsl:for-each?
the above variable context displays all values from the node instead of just counter. Isnt there anything simple like X= 1 ; For look X=X+1
display X.
Thanks'
Ash
-
- Posts: 8
- Joined: Tue Oct 02, 2012 4:53 am
Re: A Simple Counter
K after some research decided to use position() function
<xsl for-each>
<countNo><xsl:value-of select="position()"/></countNo>
</xsl for-each>
This works fine. But I want to save the value into a variable and then print the total lines after the for loop. So i did this.
<xsl for-each>
<countNo><xsl:variable name="rownum" select="position()"></countNo>
</xsl for-each>
<xsl:value-of select=@rownum"/>
This does not work. Any ideas??
<xsl for-each>
<countNo><xsl:value-of select="position()"/></countNo>
</xsl for-each>
This works fine. But I want to save the value into a variable and then print the total lines after the for loop. So i did this.
<xsl for-each>
<countNo><xsl:variable name="rownum" select="position()"></countNo>
</xsl for-each>
<xsl:value-of select=@rownum"/>
This does not work. Any ideas??
-
- Posts: 8
- Joined: Tue Oct 02, 2012 4:53 am
Re: A Simple Counter
Sorry i put the wrong sytax. It should be $ instead of @.
But still I get an error message that Variable rownum has not been delcared. Here is the code. When I try to declare the variable rownum above the for-each statement, then I get a message that variable already defined on the statement that's within the loop.
<xsl:for-each select="/env:Envelope/env:Body/
<xsl:variable name="rownum" select="position()"/>
</xsl:for-each>
<xsl:text>
</xsl:text>
<xsl>Total Row Count:</xsl>|<xsl:value-of select="$rownum"/>
But still I get an error message that Variable rownum has not been delcared. Here is the code. When I try to declare the variable rownum above the for-each statement, then I get a message that variable already defined on the statement that's within the loop.
<xsl:for-each select="/env:Envelope/env:Body/
<xsl:variable name="rownum" select="position()"/>
</xsl:for-each>
<xsl:text>
</xsl:text>
<xsl>Total Row Count:</xsl>|<xsl:value-of select="$rownum"/>
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: A Simple Counter
You can't use a variable declared in an xsl:for-each loop outside of that loop (it's the same as in procedural programming, at least Java/C).
If you just want to count the number of elements use the count() function:
e.g.
<xsl>Total Row Count:</xsl>|<xsl:value-of select="count(/env:Envelope/env:Body/)"/>
Regards,
Adrian
If you just want to count the number of elements use the count() function:
e.g.
<xsl>Total Row Count:</xsl>|<xsl:value-of select="count(/env:Envelope/env:Body/)"/>
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service