I know there are similar, more complex posts around, but I just can’t get this simple thing to work. I have a very very simple XSLT loop, which I just need to run 5 times over. That’s it.
Here’s what I have:
<xsl:template match="/">
<div id="container">
<xsl:for-each select="$currentPage/myItems/data/item">
<img src="image.gif" />
</xsl:for-each>
</div>
</xsl:template>
This works fine, I just need to loop this part:
<xsl:for-each select="$currentPage/myItems/data/item">
<img src="image.gif" />
</xsl:for-each>
five times over, so that the output is literally just repeated 5 times. I don’t want to just copy and paste it five times (although that does work) as there’s got to be a better way to handle it.
Can anyone point me in the right direction on this? Thanks!
The only imperative looping construct in XSLT is
for-eachbut that loops over nodes in the input document. If you don’t want to implement using recursion, put the inside of the loop in a named template and then usecall-templatefive times to call it.Something like:
and then where you want to call this: