Re: [xsl] Test expression : Is Context Node an ancestor of node with Id!

Subject: Re: [xsl] Test expression : Is Context Node an ancestor of node with Id!
From: "Joris Gillis" <roac@xxxxxxxxxx>
Date: Sat, 19 Feb 2005 08:33:40 +0100
Tempore 02:52:24, die 02/19/2005 AD, hinc in xsl-list@xxxxxxxxxxxxxxxxxxxxxx scripsit Adam J Knight <adam@xxxxxxxxxxxxxxxxx>:

     <xsl:choose>
        <xsl:when test="@id=$id | ancestor::tree_node[@id=$id]">
        </xsl:when>
        <xsl:otherwise>
        </xsl:otherwise>
  </xsl:choose>

Hi,


1)The union operater '|' works only for node-sets, not boolean value. Use 'or' here.
2)'ancestor' should become 'descendant'


Suppose you have this:
<xsl:template select="foo">
<xsl:if test="ancestor::bar">
Hooray
</xsl:if>
</xsl:template>
The 'xsl:if' will *not* test that the context node ('foo') is an ancestor of 'bar'.
The oppposite is true:
It will test wether 'foo' has an ancestor named 'bar'.


This is because 'ancestor' is an axis (containing all ancestors of the context node), not a boolean test or something alike.

I do hope this clears it a bit. If you did not understand at first reading, I advise you to read this again.


I want to use a test expression to test whether the node currently matched
(context node?)
correct
is an ancestor of a node with a specified id.


  <xsl:choose>
        <xsl:when test="descendant-or-self::tree_node[@id=$id]">
        </xsl:when>
        <xsl:otherwise>
        </xsl:otherwise>
  </xsl:choose>

regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041)
Veni, vidi, wiki (http://www.wikipedia.org)

Current Thread