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

Re: getting text nodes of subtree?

Subject: Re: getting text nodes of subtree?
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Fri, 28 Jun 2002 12:01:27 +0100
xml get node subtree
Hi Jakub,

> how can I get string which contains text nodes of all children of
> given element?

Usually, just getting the string value of a node will do that.

> for example what will return
>
> <a>
>   aaa
>   <b>
>     bbb
>     <c>
>       ccc
>     </c>
>     BBB
>   </b>
>   AAA
> </a>

It's very easy from this example to get the string:

"  aaa

    bbb

      ccc

    BBB

  AAA
"
Just do:

  <xsl:value-of select="/a" />

But to get the string that you want:

> aaabbbcccBBBAAA

you need to get rid of the whitespace that's been added to the tree.
The easiest thing to do here is to have a template in 'string' mode
that matches text nodes and gives the normalized value of the string:

<xsl:template match="text()" mode="string">
  <xsl:value-of select="normalize-space()" />
</xsl:template>

and then apply templates to the a element in 'string' mode; the built
in templates will move through the tree to get to the text nodes, and
their normalized values will be returned, concatenated together:

  <xsl:apply-templates select="/a" mode="string" />

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 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.