I need to sort an XML subtree using a value in a different matching subtree
in the same document.

The XSLT syntax I am using is (indented so that sort select and VAL
definition line up:


<xsl:for-each select='LABITEM0'>
<xsl:sort select='ancestor::TABLE/DATA/DIMN[@idx=current()/
@dimn_idx]/DIMN[@idx=$RANKCOL_IDX]/CELL/ITEM[contains($FIGTYPE,@class)][1]'
order='descending' data-type='number'/>
<xsl:variable name='VAL' select='/TABLE/DATA/DIMN[@idx=current()/
@dimn_idx]/DIMN[@idx=$RANKCOL_IDX]/CELL/ITEM[contains($FIGTYPE,@class)]
[1]'/>
<xsl:copy>
<xsl:copy-of select='@*'/>
<xsl:attribute name='ORD'><xsl:value-of select='position
()'/></xsl:attribute>
<xsl:attribute name='VAL'><xsl:value-of select='$VAL'/>
</xsl:attribute>
<xsl:copy-of select='*'/>
</xsl:copy>
</xsl:for-each>

This works fine using another XSLT processor (xsltproc)
BUT IS RETURNED UNSORTED (i.e. in original document order) using
XslTransform (and also msxml (4.0) from the command line).

The VAL attribute is correctly set - so I am pointing to the right values.

I've tried other sorts that do not use a path starting at the document root
and they seem to work OK.

Can anyone tell me why this isn't working - or suggest a sort select syntax
that would work?

Re: Sorting Problem by Lenonardo

Lenonardo
Thu Jun 10 12:06:18 CDT 2004

Amendment - I pasted the incorrect syntax as I have been trying so many
options. The previously pasted syntax still does not work - but the
actual syntax I am querying does NOT use the ancestor:: axis - and start
with /TABLE/DATA/DIMN/... - exactly as in the definition of $VAL.

Thanks

Lenonardo <leonardo@duckpond.co.uk> wrote in
news:Xns9504B72ACF4FCM3141T@207.46.248.16:

> I need to sort an XML subtree using a value in a different matching
> subtree in the same document.
>
> The XSLT syntax I am using is (indented so that sort select and VAL
> definition line up:
>
>
><xsl:for-each select='LABITEM0'>
> <xsl:sort select='ancestor::TABLE/DATA/DIMN[@idx=current()/
> @dimn_idx]/DIMN[@idx=$RANKCOL_IDX]/CELL/ITEM[contains($FIGTYPE,@class)]
> [1]'
> order='descending' data-type='number'/>
><xsl:variable name='VAL' select='/TABLE/DATA/DIMN[@idx=current()/
> @dimn_idx]/DIMN[@idx=$RANKCOL_IDX]/CELL/ITEM[contains($FIGTYPE,@class)]
> [1]'/>
> <xsl:copy>
> <xsl:copy-of select='@*'/>
> <xsl:attribute name='ORD'><xsl:value-of
> select='position
> ()'/></xsl:attribute>
> <xsl:attribute name='VAL'><xsl:value-of
> select='$VAL'/>
></xsl:attribute>
> <xsl:copy-of select='*'/>
> </xsl:copy>
></xsl:for-each>
>
> This works fine using another XSLT processor (xsltproc)
> BUT IS RETURNED UNSORTED (i.e. in original document order) using
> XslTransform (and also msxml (4.0) from the command line).
>
> The VAL attribute is correctly set - so I am pointing to the right
> values.
>
> I've tried other sorts that do not use a path starting at the document
> root and they seem to work OK.
>
> Can anyone tell me why this isn't working - or suggest a sort select
> syntax that would work?
>