This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: getting text nodes of subtree?
- From: Jeni Tennison <jeni at jenitennison dot com>
- To: Jakub dot Valenta at Deio dot net
- Cc: XSL-List at lists dot mulberrytech dot com
- Date: Fri, 28 Jun 2002 12:01:27 +0100
- Subject: Re: [xsl] getting text nodes of subtree?
- Organization: Jeni Tennison Consulting Ltd
- References: <OF644457FA.8C9F10DF-ONC2256BE6.0038B35F@e-know.net>
- Reply-to: xsl-list at lists dot mulberrytech dot com
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