Select Categories Below
Advertisement
Start Your Own Q&A Site
Create your own Q&A site easily, allowing you to quickly grow a new community around any subject matter or generate new organic traffic for your existing website.
Status: Closed Points: 75 Time: 02:27 - Dec 19, 2006
dustPuppy
I need to call a template 5 times, so I need to make something like for (int i = 1; i <=5; i++) { xxx } How is that accomplished in xslt?
Categories:
Add Categories
When adding more than one category, separate them with commas.
Date:: Dec 19, 2006
Time:: 02:50
I found this way, that should work supposedly: <xsl:for-each select="//*[position() <= 5]"> </xsl:for-each> But it only does the first step of the loop.
Time:: 03:30
It seems this is not the "right" way to use XSLT after all: "incrementing a counter is a procedural programming solution, while XSLT is a functional language. Sometimes you do have to resort to using recursion or an extension, but often there is a way to achieve the results you want without resorting to using a counter at all, let alone incrementing it. The most common problems are solved using careful selection of nodes using the select attribute on an xsl:for-each or xsl:apply-templates, and utilizing position() when processing those nodes." Quoted from: http://www.xslt.com/html/xsl-list/2002-0...
Time:: 03:35
This is the best way to do it (recursively): <xsl:template name="for.loop"> <xsl:param name="i" /> <xsl:param name="count" /> <!--begin_: Line_by_Line_Output --> <xsl:if test="$i <= $count"> <br /> <b><xsl:value-of select="$i" />.</b>Hello world! </xsl:if> <!--begin_: RepeatTheLoopUntilFinished--> <xsl:if test="$i <= $count"> <xsl:call-template name="for.loop"> <xsl:with-param name="i"> <xsl:value-of select="$i + 1"/> </xsl:with-param> <xsl:with-param name="count"> <xsl:value-of select="$count"/> </xsl:with-param> </xsl:call-template> </xsl:if> </xsl:template> <xsl:call-template name="for.loop"> <xsl:with-param name="i">1</xsl:with-param> <xsl:with-param name="count">10</xsl:with-param> </xsl:call-template>
xarcus
Time:: 10:23
XSL is based on a "transformation" model The best way to follow the model is to make appear an element 5 times on the source xml
Date:: Feb 10, 2007
Time:: 06:04
gotta close this one... Xarcus, good comment there :)
mrousseva
Date:: Jan 31, 2012
Time:: 18:25
use similar to this: <xsl:for-each select="1 to xs:integer($srcNode/cellData[nodeId = $nodeId]/level - 1)"> where $srcNode/cellData[nodeId = $nodeId]/level - 1) returnes some valid integer
Question Answered
This question has been closed, and points have been rewarded to the following experts:
You're welcome however to comment or give additional information or if you wish, you have the ability to write a Tutorial in the Tutorial Area.
Answer this Question
New User
Email:
Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address
Registered User
Username:
Password:
Forgot Your Password?
Enter your email address below and we will resend your login information to you.
Login Information Sent
Questions
how to use xsl:call-template with a node as a parameter?
You have 100 characters to use
Rank
Expert
Points
1.
10354
2.
6493
3.
5596
4.
4848
5.
3487
6.
2840
7.
2770
8.
2303
9.
1820
10.
917
Register today to share your knowledge with the community and be recognized and rewarded for your contributions.
Register Here
"Psst, Quomon is a great site. Pass it on." Tell a Friend | Link To Us | Save to Delicious | Digg it
Language Options
English:
Español:
Sponsors
Questions and Answers Software