[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Processing based on number - alternatives to recu
xslt 2.0 <xsl:for-each select="1 to ."> ... </xsl:for-each> On Tue, Mar 4, 2008 at 7:10 PM, Michael Ludwig <mlu@xxxxxxxxxxxxx> wrote: > 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? > > 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|