Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
vijendra singh
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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">
<xslutput 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>
<xsltherwise>
<xsl:message terminate="yes">
</xsl:message>
</xsltherwise>
</xsl:choose>
</xsl:variable>
</xsl:template>


</xsl:stylesheet>

Please guide me to proceed further.

Vijendra
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic