[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

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
xsl sort preceding sibling problem
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.