This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: Sibling sort order
- To: "'xsl-list at mulberrytech dot com'" <xsl-list at mulberrytech dot com>
- Subject: RE: Sibling sort order
- From: Richard Bell <RichardBell at rogge dot co dot uk>
- Date: Mon, 3 Apr 2000 13:52:24 +0100
- Reply-To: xsl-list at mulberrytech dot com
David, thanks for your help so far. Based on your information and the
subsequent exchange I think I understand the issue. I certainly understand
it better. If you use a select attribute to obtain a node list, the
variable element will contain a node list and you can query the path of this
node list using /, // and []. If you do not use a select statement and
instead copy the contents of a node list in the content of the variable, you
obtain a result tree fragment which does not support path based queries.
Therefore, in order to sort the content of the variable, you cannot use a
select statement. Sadly, for my puposes this does not help. The method
behind my madness was yet another grouping methodology. I had intended to
use the relationship between the siblings to determine when the group
field(s) had changed enabling me to process group header(s)/footer(s) etc...
However, in order to do this I need to be able to reference the siblings in
sorted order and I cannot do this unless I use a select statement. It seems
that my only recourse is to use a 2 stage method and transform the data
first into a ordered list before transforming into the output. The example
below illustrates where I am on this one.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="root">
<xsl:variable name="x" select="*"/>
<xsl:variable name="y">
<xsl:for-each select="*">
<xsl:sort select="attribute::f1"/>
<xsl:copy-of select="."/>
</xsl:for-each>
</xsl:variable>
<xsl:apply-templates select="$x"/>
<xsl:apply-templates select="$y"/>
</xsl:template>
<xsl:template match="row">
<xsl:variable name="pos" select="position()-1"/>
<div>
<xsl:value-of select="attribute::f1"/>
<xsl:value-of select="parent::*/*[position()=$pos]/attribute::f1"/>
</div>
</xsl:template>
</xsl:stylesheet>
<root>
<row f1="c"/>
<row f1="b"/>
<row f1="a"/>
</root>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list