This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: xsl:sort
- To: Dave Pawson <daveP at dpawson dot freeserve dot co dot uk>
- Subject: Re: xsl:sort
- From: Jeni Tennison <jeni at friday dot u-net dot com>
- Date: Sun, 06 Aug 2000 16:23:38 +0100
- Cc: xsl-list at mulberrytech dot com
- Reply-To: xsl-list at mulberrytech dot com
Dave,
>Does a sort use the key *only* for sorting,
>i.e. can I keep the function and its children together
>durin the sort?
>
> <xsl:template match="faqindex">
> <H2>Index for XSLT FAQ Website</H2>
> <!-- Sort the functions -->
> <xsl:variable name="fns">
> <xsl:for-each select="functions[.!='']">
> <xsl:sort data-type="text" select="pair/word"/>
> </xsl:for-each>
> </xsl:variable>
>
><!-- now convert that to a node-set and step through it -->
>
> <xsl:for-each select="xt:node-set($fns)">*
> <xsl:value-of select="child::*/text()"/> <br />
> </xsl:for-each>
> </xsl:template>
You've probably slapped your head and sent a mail retracting this question
that's going to cross this reply in the post, but anyway:
You've said:
<xsl:variable name="fns">
<xsl:for-each select="functions[.!='']">
<xsl:sort data-type="text" select="pair/word"/>
</xsl:for-each>
</xsl:variable>
The xsl:for-each loops over each of the functions, sorted in terms of
pair/word and then... does nothing with them! Since there's nothing there
that actually produces any output, then the variable $fns is set to an
empty rtf. When it's passed to the next for-each, there's nothing to
iterate over.
What you wanted was:
<xsl:variable name="fns">
<xsl:for-each select="functions[.!='']">
<xsl:sort data-type="text" select="pair/word"/>
<xsl:copy-of select="." />
</xsl:for-each>
</xsl:variable>
i.e. to produce a copy of each of the sorted functions to process later on.
[I guess there's a good reason for storing the sorted list and using an
extension function to access it rather than just doing:
<xsl:for-each select="functions[.!='']">
<xsl:sort data-type="text" select="pair/word" />*
<xsl:value-of select="child::*/text()"/> <br />
</xsl:for-each>]
I hope that this helps,
Jeni
Dr Jeni Tennison
Epistemics Ltd * Strelley Hall * Nottingham * NG8 6PE
tel: 0115 906 1301 * fax: 0115 906 1304 * email: jeni.tennison@epistemics.co.uk
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list