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]

Re: Interpretation of preceding axis (preceding-sibling in particular)


Hi John-Paul,

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

Sort of. Whenever you apply templates to a node set with
xsl:apply-templates to iterate over them with xsl:for-each, they are
processed in document order. The position() function shows you that
numbering.

On the other hand, when you use a predicate in a step, the predicate
treats the nodes selected by the step in the order determined by the
axis used by the step.

So if you do:

  <xsl:for-each select="preceding::element">
    <xsl:if test="position() = 1">
      <xsl:value-of select="." />
    </xsl:if>
  </xsl:for-each>

then you will get the value of the first 'element' element in the
document (excluding ancestors), but if you do:

  <xsl:for-each select="preceding::element[1]">
    <xsl:value-of select="." />
  </xsl:for-each>

then you will get the value of the 'element' element that occurs
immediately before the one you're currently on.

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.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]