Subject: Re: [xsl] Filling gaps in a list of values From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Tue, 22 Jan 2002 14:55:10 +0000 |
Hi Ben, > Is it possible to sort the nodes and put them in a variable. ie > > <xsl:variable name="sorted"> > <xsl:for-each select="nodes[@order]"> > <xsl:sort select="@order" order="descending"/> > <xsl:copy-of select="current()"/> > </xsl:for-each> > </xsl:variable> > > (I know this doesn't work but could it work with the correct lines > of code? Or is it fatally flawed?) Yes, you can do this, but when you set a variable via its content then it gets set to a result tree fragment. To get any information out of the result tree fragment, you need to convert it to a node set using an extension node-set() function (whatever one your processor supports). This wouldn't be a bad method of getting the minimum and maximum values for the recursion, considering that you get both the minimum and maximum at the same time. You'd have to see, but it's likely that a recursive method (or even better, a built-in extension function) would be faster, but this is fairly simple. If I were doing it, I'd try to make the result tree fragment quite small, so simply make it: <xsl:variable name="minAndMax-rtf"> <xsl:for-each select="node[@order]"> <xsl:sort select="@order" order="descending" data-type="number" /> <xsl:choose> <xsl:when test="position() = 1"> <max><xsl:value-of select="@order" /></max> </xsl:when> <xsl:when test="position() = last()"> <min><xsl:value-of select="@order" /></min> </xsl:when> </xsl:choose> </xsl:for-each> </xsl:variable> And then do: <xsl:variable name="minAndMax" select="exsl:node-set($minAndMax-rtf)/*" /> <xsl:call-template name="countDown"> <xsl:with-param name="from" select="$minAndMax/max" /> <xsl:with-param name="to" select="$minAndMax/min" /> </xsl:call-template> Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Filling gaps in a list of, Ben Hesketh | Thread | [xsl] combining property lists with, saodl |
Re: [xsl] Filling gaps in a list of, Jeni Tennison | Date | [xsl] combining property lists with, saodl |
Month |