4 users online. Create an account or sign in to join them.Users
outputting a certain number of elements
This is an open discussion with 5 replies, filed under XSLT.
Search
Not sure if I understand you correctly, but...
<xsl:template match="/">
<ul>
<xsl:call-template name="generate">
<xsl:with-param name="to" select="5" />
</xsl:call-template>
</ul>
</xsl:template>
<xsl:template name="generate">
<xsl:param name="count">1</xsl:param>
<xsl:param name="to" select="10" />
<li>item <xsl:value-of select="$count" /></li>
<xsl:if test="$count < $to">
<xsl:call-template name="generate">
<xsl:with-param name="count" select="$count + 1" />
<xsl:with-param name="to" select="$to" />
</xsl:call-template>
</xsl:if>
</xsl:template>
Or try out Nick's alternative 'for' loop using XSLT and template callbacks.
Woah I forgot all about that, well remembered.
(Need to rebuild my blog and make this stuff more easy to read).
Alpacaaa's solution works perfect for my case. Although i am not sure if i understand it fully
looks like the if statement is called untill it reached the set value (5 in this case, mine is a variable value)
The 'to' parameter is now set to 10 but can be anything larger then 1, am i right?
Nick's solution most probably works fine too, but seems a bit more complex, so i just go with alpacaa's solution, thanks!
10 is default, but you can override it specifing the to param while calling the template.
Create an account or sign in to comment.
I would like to output a list with a certain number of list items in xslt
for example dynamicly create 5 listitems in xslt:
<ul> <li>listitem1</li> <li>listitem2</li> <li>listitem3</li> <li>listitem4</li> <li>listitem5</li> </ul>How can i do this?