This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: xsl sorting
- From: Jarno dot Elovirta at nokia dot com
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Wed, 17 Apr 2002 09:24:50 +0300
- Subject: RE: [xsl] xsl sorting
- Reply-to: xsl-list at lists dot mulberrytech dot com
Heppa,
> If there is several sorting orders, they are all applied and not
> only the last one. For example if there is xml file that includes
> severals sets like:
>
> <Subject id="0000000001" id2="001" id3="001">Juu juu</Subject>
> <Subject id="0000000001" id2="002" id3="002">RE:Juu juu</Subject>
> <Subject id="0000000001" id2="002" id3="001">RE:Juu juu</Subject>
>
> and sets are sorted:
> <xsl:sort select="Subject/@id" order="ascending" />
> <xsl:sort select="Subject/@id2" order="ascending" />
> <xsl:sort select="Subject/@id3" order="ascending" />
>
> So the result would be:
> <Subject id="0000000001" id2="001" id3="001">Juu juu</Subject>
> <Subject id="0000000001" id2="002" id3="001">RE:Juu juu</Subject>
> <Subject id="0000000001" id2="002" id3="002">RE:Juu juu</Subject>
>
> Right?
Right, but make sure when you're using the sort instruction that your context node is the corrent one for the sort select expressions. If you have
<xsl:for-each select="Subject">
<xsl:sort select="Subject/@id" order="ascending" />
<xsl:sort select="Subject/@id2" order="ascending" />
<xsl:sort select="Subject/@id3" order="ascending" />
<xsl:copy-of select="." />
</xsl:for-each>
that will not work, because the Subject doesn't have a Subject child. Instead use
<xsl:template match="f">
<xsl:for-each select="Subject">
<xsl:sort select="@id" order="ascending" />
<xsl:sort select="@id2" order="ascending" />
<xsl:sort select="@id3" order="ascending" />
<xsl:copy-of select="." />
</xsl:for-each>
</xsl:template>
Cheers,
Santtu
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list