Subject: [xsl] Processing based on number - alternatives to recursion? From: Michael Ludwig <mlu@xxxxxxxxxxxxx> Date: Tue, 04 Mar 2008 17:10:36 +0100 |
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 > . )"><!-- Greater than me? --> <xsl:value-of select="concat( $iter, ' ' )"/> <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?
Or is this misguided optimization thinking in thinking that lots of template invocations are bad?
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Looking for a good Docboo, Florent Georges | Thread | Re: [xsl] Processing based on numbe, Vyacheslav Sedov |
RE: [xsl] Use of data() function, Michael Kay | Date | Re: [xsl] Use of data() function, Martin Honnen |
Month |