Altova Mailing List Archives


[xsl] preceding-sibling after sort gives unexpected result

From: Kaine Varley <kaine.varley@------------>
To:
Date: 9/11/2003 9:15:00 AM
Hi,

I am trying to process a document similar to the one below, using the
stylesheet below. My problem is that after I have performed the sort, I
appear to get the preceding sibling in the original document order rather
than in the newly sorted order.

Looking at the results, you can see that for result number 4, I was hoping
to get (a) as my preceding sibling, and not (c), which was the original
document order.

This is an unexpected result, and not at all what I was hoping for. Is this
supposed to happen, or is this just a quirk of MSXML?


Kaine


Source XML:
-----------
<root>
	<parent>
		<child name="a">40</child>
		<child name="b">60</child>
		<child name="c">50</child>
		<child name="d">30</child>
		<child name="e">20</child>
	</parent>
</root>


Stylesheet:
-----------
<xsl:template match="root">
	<results>
		<xsl:apply-templates select="parent"/>
	</results>
</xsl:template>


<xsl:template match="parent">
	<xsl:apply-templates select="child">
		<xsl:sort select="." data-type="number" order="descending"/>
	</xsl:apply-templates>
</xsl:template>


<xsl:template match="child">
	<result number="{position()}">
		<current-child-name>
			<xsl:value-of select="@name"/>
		</current-child-name>
		<current-child-value>
			<xsl:value-of select="."/>
		</current-child-value>
		<preceding-sibling-name>
			<xsl:value-of
select="preceding-sibling::child[1]/@name"/>
		</preceding-sibling-name>
	</result>
</xsl:template>


Result:
-------
<results>
	<result number="1">
		<current-child-name>b</current-child-name>
		<current-child-value>60</current-child-value>
		<preceding-sibling-name>a</preceding-sibling-name>
	</result>
	<result number="2">
		<current-child-name>c</current-child-name>
		<current-child-value>50</current-child-value>
		<preceding-sibling-name>b</preceding-sibling-name>
	</result>
	<result number="3">
		<current-child-name>a</current-child-name>
		<current-child-value>40</current-child-value>
		<preceding-sibling-name/>
	</result>
	<result number="4">
		<current-child-name>d</current-child-name>
		<current-child-value>30</current-child-value>
		<preceding-sibling-name>c</preceding-sibling-name>
	</result>
	<result number="5">
		<current-child-name>e</current-child-name>
		<current-child-value>20</current-child-value>
		<preceding-sibling-name>d</preceding-sibling-name>
	</result>
</results>


Post sort:
----------
<root>
	<parent>
		<child name="b">60</child>
		<child name="c">50</child>
		<child name="a">40</child>
		<child name="d">30</child>
		<child name="e">20</child>
	</parent>
</root>


My system:
----------
XP Professional
IE6 SP2
MSXML4 SP2


SNIP



PROACTIS Group Limited
Holtby Manor, Stamford Bridge Road, York, YO19 5LL
Tel +44 (0)1904 481999 Fax +44 (0)1904 481666
Visit us at www.proactis.com <http://www.proactis.com/> 

PROACTIS (r) - Control spend.  Streamline purchasing.

************************************************************
The information contained in this email is intended only for the individual
to whom it is addresses.  It may contain privileged and confidential
information.  If you have received this message in error or there are any
problems, please notify the sender immediately and delete the message from
your computer.  The unauthorised use, disclosure, copying or alteration of
this message is forbidden.  PROACTIS Group Limited will not be liable for
direct, special, indirect or consequential damage as a result of any virus
being passed on, or arising from alteration of the content of this message
by a third party.
************************************************************

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

Disclaimer

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.