This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Interpretation of preceding axis (preceding-sibling in particular)



Hi,

   I have read several of the threads on the preceding axes and looked 
at the FAQ but I am still not 100% sure what should be returned.  I 
have built a stylesheet and an input file to illustrate the issue. It 
tests the actual node set returned as well as the position of those 
nodes.

xslt file
==========

<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version = "1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:template match = "/document" >
  <xsl:apply-templates select="element[1]"  mode = "siblings"/>
  <xsl:apply-templates select="element[5]"  mode = "siblings"/>
  <xsl:apply-templates select="element[10]" mode = "siblings"/>
</xsl:template>

<xsl:template match = "element" mode = "siblings">
  <xsl:call-template name = "siblings"/>
</xsl:template>


<xsl:template match = "element" mode = "position"><xsl:value-of select = "position()"/></xsl:template>

<xsl:template name = "siblings">
Context Node:         <xsl:value-of select = "."/>
Preceeding Siblings:  <xsl:apply-templates select="preceding-sibling::element"/>
Preceeding Position:  <xsl:apply-templates select="preceding-sibling::element" mode = "position"/>
Following Siblings:   <xsl:apply-templates select="following-sibling::element"/>
Following Position:   <xsl:apply-templates select="following-sibling::element" mode = "position"/>
</xsl:template>

</xsl:stylesheet>
--------------------

xml file

<?xml version = "1.0" standalone = "yes" ?>
<document>
  <element pos = "1">1</element>
  <element pos = "2">2</element>
  <element pos = "3">3</element>
  <element pos = "4">4</element>
  <element pos = "5">5</element>
  <element pos = "6">6</element>
  <element pos = "7">7</element>
  <element pos = "8">8</element>
  <element pos = "9">9</element>
  <element pos = "10">0</element>
</document>

--------------------------------------

I got the following output from XT

Context Node:         1
Preceeding Siblings:
Preceeding Position:
Following Siblings:   234567890
Following Position:   123456789

Context Node:         5
Preceeding Siblings:  1234
Preceeding Position:  1234
Following Siblings:   67890
Following Position:   12345

Context Node:         0
Preceeding Siblings:  123456789
Preceeding Position:  123456789
Following Siblings:
Following Position:

This position values seem incorrect to me.  I would have expected the 
positions to be reversed (ie 4321 and 987654321).  It seems clear to me
that the reverse axes are counted from the context node backwards.  The 
immediately previous node should be 1.  

The actual node ordering appears to be correct.  Regardless of the 
axis the nodes are returned in document order, only the position 
changes.  Is this interpretation correct?

						John-Paul

----------------------
John-Paul Sicotte
Software Composer
MessagingDirect
mailto:John-Paul.Sicotte@MessagingDirect.com



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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]