Subject: RE: xsl:sort order problems
From: DPawson@xxxxxxxxxxx
Date: Mon, 29 Nov 1999 12:27:24 -0000
|
Many thanks David. That's been giving me heartache for about two weeks!
Your point about axis specifiers referring to document order
clarifies things greatly.
I am happier without using extensions :-)
regards, DaveP
>-----Original Message-----
>From: David Carlisle [mailto:davidc@xxxxxxxxx]
>Sent: 29 November 1999 11:08
>To: xsl-list@xxxxxxxxxxxxxxxx
>Subject: Re: xsl:sort order problems
>
>
>
>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 " 
">
>]>
>
>
> <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
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|