[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

inconsistent Preceding-Sibling behaviour when nested i

Subject: inconsistent Preceding-Sibling behaviour when nested in For-Each
From: Alan Stein <as2@xxxxxxxxxxx>
Date: Fri, 01 Nov 2002 22:25:07 -0500
xsl if preceding sibling

I've observed a reproducible XSL behaviour that I just can't understand. "preceding-sibling", "following-sibling", and conditional expressions based on these axes appear to behave oddly when placed in a "for-each" element.


My observations of the unusual behavior within the "for-each" loop:

-- "following-sibling" behaves exactly as I would expect
-- "preceding sibling" unexpectedly always refers to the first sibling in the document
-- "if" statements behave erraticly: neither comparisons of current nodes to "preceding-sibling" nor comparisons to "following-sibling" appear to work completely.


I've listed some sample code below to demonstrate the problem.

Thanks much for any help with this.
  --Alan


Example:


My XML file:

<joblist>
	<person>
		<name>frank</name>
		<job>cook</job>
	</person>
	<person>
		<name>frank</name>
		<job>clean</job>
	</person>
	<person>
		<name>joe</name>
		<job>drive</job>
	</person>
	<person>
		<name>chris</name>
		<job>clean</job>
	</person>
	<person>
		<name>chris</name>
		<job>drive</job>
	</person>
</joblist>


My XSL file:


<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="joblist">
<xsl:for-each select="./person">
++++++++++++++++++++++++++++
<br/>
CurName=<xsl:value-of select="./name"/><br/>
CurJob=<xsl:value-of select="./job"/><br/>
<br/>
PrevName=<xsl:value-of select="./preceding-sibling::node()/name"/><br/>
PrevJob=<xsl:value-of select="./preceding-sibling::node()/job"/><br/>
NextName=<xsl:value-of select="./following-sibling::node()/name"/><br/>
NextJob=<xsl:value-of select="./following-sibling::node()/job"/><br/>
<br/>
<xsl:if test="./name=./preceding-sibling::node()/name">Name Match with Previous<br/></xsl:if>
<xsl:if test="./name=./following-sibling::node()/name">Name Match with Next<br/></xsl:if>
<xsl:if test="./job=./preceding-sibling::node()/job">Job Match with Previous<br/></xsl:if>
<xsl:if test="./job=./following-sibling::node()/job">Job Match with Next<br/></xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>



The Unexpected Output:


++++++++++++++++++++++++++++
CurName=frank
CurJob=cook

PrevName=
PrevJob=
NextName=frank
NextJob=clean

Name Match with Next
++++++++++++++++++++++++++++
CurName=frank
CurJob=clean

PrevName=frank
PrevJob=cook
NextName=joe
NextJob=drive

Name Match with Previous
Job Match with Next
++++++++++++++++++++++++++++
CurName=joe
CurJob=drive

PrevName=frank
PrevJob=cook
NextName=chris
NextJob=clean

Job Match with Next
++++++++++++++++++++++++++++
CurName=chris
CurJob=clean

PrevName=frank
PrevJob=cook
NextName=chris
NextJob=drive

Name Match with Next
Job Match with Previous
++++++++++++++++++++++++++++
CurName=chris
CurJob=drive

PrevName=frank
PrevJob=cook
NextName=
NextJob=

Name Match with Previous
Job Match with Previous






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



Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.