0

I am in need to create a element five times in xslt 1.0

so that output would be

<element1></element1>
<element1></element1>
<element1></element1>
<element1></element1>
<element1></element1>

Is there any loop like for(int i=1;i<=5;i++) in xslt. Many pages suggest array but in xslt 2.0

Raj
  • 343
  • 3
  • 13

1 Answers1

1

If you have a variable but not-too-large number, you can use simple recursion

<xsl:template name="doelements">
   <xsl:param name="howmany" select="0"/>
   <xsl:if test="$howmany  &gt; 0">
      <element1/>
      <xsl:call-template name="doelements">
          <xsl:with-param name="howmany">
             <xsl:value-of select="$howmany - 1"/>
          </xsl:with-param>
      </xsl:call-template>
   </xsl:if>
</xsl:template>

so where you want 5 of them you would call

      <xsl:call-template name="doelements">
          <xsl:with-param name="howmany">
             <xsl:value-of select="5"/>
          </xsl:with-param>
      </xsl:call-template>

(didn't check, might be off-by-one, left as an excercise to the reader ;-)

Stefan Hegny
  • 2,107
  • 4
  • 23
  • 26