Altova Mailing List Archives

[xsl] Interpretation of preceding axis (preceding-sibling in particular)

From: John-Paul Sicotte <jps@------------------->
Date: 8/3/2001 8:59:00 AM

   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 

xslt file

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

<xsl:stylesheet version = "1.0"

<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 match = "element" mode = "siblings">
  <xsl:call-template name = "siblings"/>

<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"/>


xml file

<?xml version = "1.0" standalone = "yes" ?>
  <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>


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 Sicotte
Software Composer

 XSL-List info and archive:


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 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.