Re: xsl:sort order problems

Subject: Re: xsl:sort order problems
From: David Carlisle <davidc@xxxxxxxxx>
Date: Mon, 29 Nov 1999 11:08:13 GMT
Even when the node list is in sorted order (so the values returned by
position() reflect sorted order) the axis specifiers like
preceding-sibling refer to _document_ order.

So
 preceding-sibling::qna[1]/topic)

doesn't do what you want.

There are various postings on `grouping' in the archives that give
wprkarounds for this, or alternatively you can use extensions
eg the latest xt has a node-set function which means you can sort
the thing once and then get the result-tree back as a node list
on which the  preceding-sibling works as you expect.

See the unique sort example in the xt distrib for an example of this.

If you want to do it without extension elements then:

<?xml version="1.0" ?>

<!DOCTYPE xsl:stylesheet [
<!ENTITY sp "<xsl:text> </xsl:text>">
<!ENTITY dot "<xsl:text>.</xsl:text>">
<!ENTITY nl "&#10;&#xD;"> 
]>


 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                 version="1.0">

<xsl:output  method="xml" indent="yes" />


<xsl:template match="/">root  <!-- match on parent of group --> 
  <xsl:for-each select="doc/qna/topic[not(.=following::topic)]">
    <xsl:sort select="."/>    <!-- sort on topic -->
     <h2>TOPIC IS:  <xsl:value-of select="."/> </h2>
     <xsl:for-each select="/doc/qna[topic=current()]">
     <xsl:sort select="q"/>
      <p>  <xsl:value-of select="q"/>(<xsl:value-of select="topic"/>) </p>
    </xsl:for-each>
    </xsl:for-each>
</xsl:template>


 <xsl:template match="*" priority="-1">
************ Default **************
 </xsl:template>
</xsl:stylesheet>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread