This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: parent of child
- To: Jo Kong HO <JoK at USWebCKS dot co dot uk>
- Subject: Re: parent of child
- From: Jeni Tennison <Jeni dot Tennison at epistemics dot co dot uk>
- Date: Wed, 07 Jun 2000 17:41:17 +0100
- Cc: "'xsl-list at mulberrytech dot com'" <xsl-list at mulberrytech dot com>
- Reply-To: xsl-list at mulberrytech dot com
Joe,
>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:
<a>Test
<b>Test2</b>
<b2>Test3</b2>
</a>
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>
Or
<xsl:template match="b">
<xsl:apply-templates select=".." />
</xsl:template>
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,
Jeni
Dr Jeni Tennison
Epistemics Ltd, Strelley Hall, Nottingham, NG8 6PE
Telephone 0115 9061301 • Fax 0115 9061304 • Email
jeni.tennison@epistemics.co.uk
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list