• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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">
<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 like tacos! And this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic