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

Re: parent -child

Subject: Re: parent -child
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Thu, 19 Jul 2001 18:02:51 +0100
Re:  parent -child
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 (&#xA; indicates line breaks):

+- (element) b
   +- (text) 2&#xA;
   +- (element) c
   |  +- (text) 3
   +- (text) &#xA;
   +- (element) d
   |  +- (text) 4
   +- (text) &#xA;

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


Current Thread
  • parent -child
    • srikanth - Thu, 19 Jul 2001 11:18:55 -0400 (EDT)
      • Wendell Piez - Thu, 19 Jul 2001 12:23:09 -0400 (EDT)
      • Jeni Tennison - Thu, 19 Jul 2001 13:06:20 -0400 (EDT) <=
      • <Possible follow-ups>
      • Heather Lindsay - Thu, 19 Jul 2001 11:42:53 -0400 (EDT)
      • srikanth - Thu, 19 Jul 2001 13:53:24 -0400 (EDT)

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.