[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: parent of child

Subject: Re: parent of child
From: Jeni Tennison <Jeni.Tennison@xxxxxxxxxxxxxxxx>
Date: Wed, 07 Jun 2000 17:41:17 +0100
xsl select child by parent
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@xxxxxxxxxxxxxxxx



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.