469,352 Members | 1,697 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,352 developers. It's quick & easy.

selecting content though xpath with text()

I'm having some trouble using text() in an xsl:value-of xpath. I have the
following xml:

....
<graphemes>
<grapheme>1</grapheme>
<grapheme>2</grapheme>
<grapheme>3</grapheme>
</graphemes>
....

and I want to xslt it into just "<graphemes>123</graphemes>". I used the
following xslt:

<xsl:template match="graphemes">
<graphemes><xsl:value-of select="./text()"></graphemes>
</xsl:template>

but that results in "<graphemes/>" being generated. If I use
select="./node()" instead, I just get "<graphemes>1</graphemes>"

how should I be doing this?
- Mike Kamermans

Jul 20 '05 #1
2 14983
> <graphemes>
<grapheme>1</grapheme>
<grapheme>2</grapheme>
<grapheme>3</grapheme>
</graphemes>

I want to xslt it into just "<graphemes>123</graphemes>". I used the
following xslt:

<xsl:template match="graphemes">
<graphemes><xsl:value-of select="./text()"></graphemes>
</xsl:template>


Hi,

With <xsl:value-of select="./text()"> , you're selecting the immediate
text nodes of the 'graphemes' element. But this element only contains
other elements named 'grapheme'. It are these 'grapheme' elements that
contain the text nodes.
And also, 'xsl:value-of' only selects the first node.
So you should be using:
<xsl:copy-of select="grapheme/text()"/>
But if the problem is really as simple as you've posted, then just use:

<xsl:template match="graphemes">
<xsl:value-of select="."/>
</xsl:template>

regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Jul 20 '05 #2
Mike Kamermans <mo******@hotmail.com> writes:
I'm having some trouble using text() in an xsl:value-of xpath. I have the
following xml:

...
<graphemes>
<grapheme>1</grapheme>
<grapheme>2</grapheme>
<grapheme>3</grapheme>
</graphemes>
...

and I want to xslt it into just "<graphemes>123</graphemes>". I used the
following xslt:

<xsl:template match="graphemes">
<graphemes><xsl:value-of select="./text()"></graphemes>
</xsl:template>

but that results in "<graphemes/>" being generated. If I use
select="./node()" instead, I just get "<graphemes>1</graphemes>"

how should I be doing this?
- Mike Kamermans


text() selects the text nodes of graphemes which in your case just
consists of white space text noded used to indent the grapheme elements.

You don't want the text node _children_ you want teh string value of teh
whol eelement (which is the character data in all _descendants_) so just
use select="."

By default that will give you
" 1
2
3
"

If you don't want the space to be considered use

<xsl:strip-space elements="graphemes"/>

at the top level of your stylesheet.
David

Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Tjerk Wolterink | last post: by
12 posts views Thread by Lawrence Oluyede | last post: by
3 posts views Thread by larry mckay | last post: by
8 posts views Thread by Jean-François Michaud | last post: by
3 posts views Thread by requeth | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.