RE: [xsl] sort problem

Subject: RE: [xsl] sort problem
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Sun, 19 Oct 2003 23:33:34 +0100
IIRC this is a bug that has been reported before, relating to the use of
current() in an xsl:sort expression.

Michael Kay


> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Edward Maesen
> Sent: 19 October 2003 21:30
> To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] sort problem
> 
> 
> I've run into a sort problem with MSXML4 and wonder if it's a 
> bug in that processor or expected behavior. Basically, the 
> problem seems to be related to a sort where the select starts 
> at the document node. See stylesheet and sample XML below.
> 
> The stylesheet (sortTest.xsl):
> ==============================
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0" 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
> 	<xsl:template match="/">
> 		<xsl:value-of select="'&#x0A;'"/>
> 		<xsl:apply-templates select="test/content/listgroup"/>
> 	</xsl:template>
> 	<xsl:template match="listgroup">
> 		<xsl:apply-templates select="list">
> 			<!-- the next sort statement is 
> supposed to sort by @pos, but has no effect in MSXML4. It 
> does work as expected in MSXML3, Xalan 1.4 and Saxon 6.5 -->
> 			<xsl:sort 
> select="/test/data/list[@ref=current()/@id]/@pos"/>
> 		</xsl:apply-templates>
> 	</xsl:template>
> 	<xsl:template match="list">
> 		<xsl:value-of select="@id"/> - <xsl:value-of 
> select="/test/data/list[@ref=current()/@id]/@pos"/> - 
> <xsl:value-of select="."/>
> 		<xsl:value-of select="'&#x0A;'"/>
> 	</xsl:template>
> </xsl:stylesheet>
> 
> 
> The source XML:
> ===============
> <?xml version="1.0" encoding="UTF-8"?>
> <?xml-stylesheet type="text/xsl" href="sortTest.xsl"?>
> <test>
> 	<content>
> 		<!-- this is a static pre-defined content 
> section, with list elements that can be re-ordered by 
> user/session preferences. -->
> 		<listgroup>
> 			<list id="a" name="first">first list in 
> content section</list>
> 			<list id="b" name="second">second list 
> in content section</list>
> 			<list id="c" name="third">third list in 
> content section</list>
> 			<list id="d" name="fourth">fourth list 
> in content section</list>
> 		</listgroup>
> 	</content>
> 	<data>
> 		<!-- this is a session-specific section 
> (appended by an aggregation step after page request) which 
> contains the desired order of list elements in the above 
> content section. -->
> 		<list ref="a" pos="3"/>
> 		<list ref="b" pos="4"/>
> 		<list ref="c" pos="2"/>
> 		<list ref="d" pos="1"/>
> 	</data>
> </test>
> 
> Expected output:
> ================
> d - 1 - fourth list in content section
> c - 2 - third list in content section
> a - 3 - first list in content section
> b - 4 - second list in content section
> 
> Output in MXSML4:
> =================
> a - 3 - first list in content section
> b - 4 - second list in content section
> c - 2 - third list in content section
> d - 1 - fourth list in content section
> 
> 
> In MSXML4 I get the output in document order, in stead of my 
> desired/expected output. I rewrote the sort select using keys 
> but got the same result.
> 
> I tested in MSXML3, Xalan 1.4 and Saxon 6.5, which gave the 
> desired result. Did I run into an MSXML4 bug or did the older 
> processors not implement the XSLT spec correctly? From 
> reading the spec I don't see why my expected result would not 
> be allowed so I suspect a bug in MSXML4. Can anybody confirm? 
> Does anyone have a suggestion for a workaround?
> 
> Thanks,
> Edward
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


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


Current Thread