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: getting the context out of a variable


>
> another problem, which I have, is getting the context out of
> a variable.

I think what you're saying is, you have a variable containing a node-set
(let's say its a single node), and you want to find out where in the source
tree that node came from? (Your terminology is confusing, though, because
"context" in XPath doesn't mean the position of a node in the source tree,
it's to do with the way in which the node was selected by the stylesheet.)
>
> An example:
>
> <xsl:variable name="tree" select="document(tree.xml)/root"/>
>
> <xsl:template match="/">
>     <xsl:apply-templates select="$tree/node"/>
> </xsl:template>
>
> <xsl:template match="node">
>     <!-- the context is here now in the variable -->
>     <xsl:if test="@name = /page/html/node/@name">

This only tests whether the string-value of the @name attribute is the same
as the string-value of some node in the node-set "/page/html/node/@name". I
imagine what you are trying to do is to test whether the context node (whose
name is <node>) matches the XSLT pattern "/page/html/node". Perhaps you are
also trying to test which document it comes from.

The simplest way to test the ancestry of the context node is by turning the
path upside down:

<xsl:if
test="parent::node/parent::html/parent::page[not(parent::node()/parent::node
())]"

You can also use this technique to test whether the node belongs to a
particular document:

<xsl:if test="generate-id(ancestor::node()[last()]) =
generate-id($document)">

Note the use of generate-id() here, because you want to compare the identity
of two nodes, not their string-values or names.

I hope this is relevant to your problem.

Mike Kay


 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]