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