|
Subject: Re: [xsl] getting text nodes of subtree? From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Fri, 28 Jun 2002 12:01:27 +0100 |
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 |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] getting text nodes of sub, James Fuller | Thread | Re: [xsl] getting text nodes of sub, Jarkko . Moilanen |
| RE: [xsl] getting text nodes of sub, Andrew Welch | Date | Re: [xsl] getting text nodes of sub, Vasu Chakkera |
| Month |