Re: parent of child

Subject: Re: parent of child
From: Jeni Tennison <Jeni.Tennison@xxxxxxxxxxxxxxxx>
Date: Wed, 07 Jun 2000 17:41:17 +0100

>if in my code user selected node <b>, how can i detect the parent of <b>;
>which in this case is node <a>?.  Basicly i want to change the display of
><a> when someone select <b>

>From the sounds of this I'm a little worried that you're asking about using
some JavaScript or something rather than XSL - what do you mean by a user
selecting a node?

>How can I find out the parent of a select child from XSL?

In case you *are* asking a question about XSLT, I'm translating this as
'how can I find out the parent of the current node within XSL?'

The answer is that you use the 'parent' axis.

>for example, I have the following XML :
>	<a>Test</a>
>		<b>Test2</b>
>		<b2>Test3</b2>
>	</a>

I will assume that you mean:


If you have a template that matches the 'b' element, then within it you can
select the 'a' element for processing using the XPath 'parent::node()' or
simply '..'.  For example:

<xsl:template match="b">
  <xsl:apply-templates select="parent::node()" />


<xsl:template match="b">
  <xsl:apply-templates select=".." />

Note that unless you specify a template for 'a' that doesn't move on to
process the 'b' element, you will get into an infinite loop, so watch out!

I hope this helps,


Dr Jeni Tennison
Epistemics Ltd, Strelley Hall, Nottingham, NG8 6PE
Telephone 0115 9061301 ? Fax 0115 9061304 ? Email

 XSL-List info and archive:

Current Thread