This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: parent -child
- To: srikanth <srik23 at yahoo dot com>
- Subject: Re: [xsl] parent -child
- From: Jeni Tennison <mail at jenitennison dot com>
- Date: Thu, 19 Jul 2001 18:02:51 +0100
- CC: XSL-List at lists dot mulberrytech dot com
- Organization: Jeni Tennison Consulting Ltd
- References: <20010719151421.72285.qmail@web14002.mail.yahoo.com>
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi Srikanth,
> How do i read the value of the child element and print the value of
> the parent element
>
> xml:
> <a>1
> <b>2
> <c>3</c>
> <d>4</d>
> </b>
> </a>
>
> I need to check for the value of [c=3] and print 2
The simple answer would be to get the value of (using xsl:value-of)
the b element whose child c element is equal to 3:
<xsl:value-of select="b[c = 3]" />
However, the b element holds mixed content. In a tree it would look
like (
 indicates line breaks):
+- (element) b
+- (text) 2

+- (element) c
| +- (text) 3
+- (text) 

+- (element) d
| +- (text) 4
+- (text) 

So you want the normalized version of the (first) text node child of
the b element whose child c element is equal to 3:
<xsl:value-of select="normalize-space(b[c = 3]/text())" />
You can drop the normalize-space() if you don't care about the line
break being output.
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list