Project

Profile

Help

ancestor-or-self in Saxon-HE-9.8.0-14

Added by Vladimir Nesterovsky about 6 years ago

I have a following xslt that prints two messages:

<xsl:stylesheet version="3.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xsl:template match="/">
    <xsl:variable name="data" as="element()">
      <a>
        <b>
          <c/>
        </b>
      </a>
    </xsl:variable>
    
    <xsl:variable name="item" as="element()" select="($data//c)[1]"/>
    
    <xsl:message select="$item!ancestor-or-self::*!local-name()"/>
    <xsl:message select="$item!local-name(), $item!..!local-name(), $item!..!..!local-name()"/>
  </xsl:template>

</xsl:stylesheet>

Should it print the same messages?

I thought the answer is yes.

But for me the output is:

a b c

c b a

Who is wrong?


Replies (2)

RE: ancestor-or-self in Saxon-HE-9.8.0-14 - Added by Michael Kay about 6 years ago

I think the Saxon output is correct.

(a) $item ! ancestor-or-self::* ! local-name()

ancestor-or-self::* is an AxisStep. From XPath §3.3.2:

[Definition: An axis step returns a sequence of nodes that are reachable from the context node via a specified axis. Such a step has two parts: an axis, which defines the "direction of movement" for the step, and a node test, which selects nodes based on their kind, name, and/or type annotation.] If the context item is a node, an axis step returns a sequence of zero or more nodes; otherwise, a type error is raised [err:XPTY0020]. The resulting node sequence is returned in document order.

So ancestor-or-self::* delivers nodes in document order, that is (a b c)

(b) $item!local-name(), $item!..!local-name(), $item!..!..!local-name()

This explicitly selects the nodes in the order (c b a); there is no construct here that performs any re-ordering.

RE: ancestor-or-self in Saxon-HE-9.8.0-14 - Added by Vladimir Nesterovsky about 6 years ago

Thank you.

For some reason I had an impression that reverse axis produces result in reverse order. It turns out the reverse order is only within predicate of such axis.

    (1-2/2)

    Please register to reply