Forums Register Login

need to generate some numbers using loop, the number of times condition met

+Pie Number of slices to send: Send
In my xslt there is one condition with TAG called NO (generates some number everytime)
<xsl:element name="SCHEDULE_ELEMENT">
<xsl:variable name="preceding_element" select="preceding-sibling::SCHEDULE_ELEMENT[1]"/>
<xsl:element name="NO">
<xsl:value-of select="NO"/> </xsl:element>

But the number in xml comes very random like
1
1
3
1
5 or anything
now i need to generate a list of numbers,in creasing order from 1 to any (may be using for loop) the number of times this condition met. It can be any number of times.

and if it gets stored anywhere (in kind of buffer or so) the time NO tag ends it should go back to 0 or 1, so that for next xml, it won't create anything starting from, except 0 or 1.

I tried something like this:-

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="xml"/>
<xsl:variable name="NO"></xsl:variable>

<xsl:template match="NO">
<xsl:param name="no"/>
<xsl:if test="$no = 1">
<!--to generate the next value-->
<xsl:for-each select="NO" >
<xsl:value-of select="NO + 1"></xsl:value-of>
</xsl:for-each>
<xsl:call-template name="for-loop">
<xsl:with-param name="no" select="1"/>
<xsl:with-param name="increment" select="1"/>
<xsl:with-param name="operator" select= "'='" />
<xsl:with-param name="testValue" select="1"/>
</xsl:call-template>
</xsl:if>
</xsl:template>

<xsl:template name="for-loop">
<xsl:param name="no" select="1"/>
<xsl:param name="increment" select="1"/>
<xsl:param name="operator" select="'='"/>
<xsl:param name="testValue" select="1"/>
<xsl:param name="iteration" select="1"/>

<xsl:variable name="testPassed">
<xsl:choose>
<xsl:when test="starts-with($operator,'=')">
<xsl:if test="$no = $testValue">
<xsl:text>true</xsl:text>
</xsl:if>
</xsl:when>
<xsl:when test="starts-with($operator,'>=')">
<xsl:if test="$no >= $testValue">
<xsl:text>true</xsl:text>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:message terminate="yes">
</xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
</xsl:template>


</xsl:stylesheet>

Please guide me to proceed further.

Vijendra
I need a new interior decorator. This tiny ad just painted every room in my house purple.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2025 times.
Similar Threads
How to Add a Line Counter for Each XML Element in XSL?
XSLT parsing XML
[XSL-FO][docbook]Problem print line in table of contents
XSLT value-of parameter not works as xml value
need to generate some numbers using loop, the number of times condition met
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 00:51:33.