xsl-list
[Top] [All Lists]

[xsl] Processing based on number - alternatives to recursion?

2008-03-04 09:11:09
I have a numeric value in my XML and want to use it to control
some processing, say counting up until the number is reached, and
outputting a line in the process.

$ cat xtimes.xml
<Urmel>10</Urmel>

I use recursion and everything works fine. Is recursion the
preferred way to use a number to steer processing in XSL 1.0?

$ cat xtimes.xsl
<xsl:transform version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  <xsl:output method="text"/>
  <xsl:template match="Urmel"><!-- match element -->
    <xsl:call-template name="rec">
      <xsl:with-param name="iter" select="1"/>
    </xsl:call-template>
  </xsl:template>
  <xsl:template name="rec"><!-- recursive template -->
    <xsl:param name="iter"/>
    <xsl:if test="not( $iter &gt; . )"><!-- Greater than me? -->
      <xsl:value-of select="concat( $iter, '&#10;' )"/>
      <xsl:call-template name="rec"><!-- Then recurse. -->
        <xsl:with-param name="iter" select="$iter + 1"/>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
</xsl:transform>

In order to use xsl:for-each, I'd have to dispose of something
generating a node-set based on my number, wouldn't I?

Is there anything like that in XSL 1.0 or 2.0?

Would that somehow be better?

Or is this misguided optimization thinking in thinking that lots of
template invocations are bad?

Michael

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--