472,337 Members | 1,591 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,337 software developers and data experts.

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 15068
> <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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Alastair Cameron | last post by:
VB6, MSXML 3.2 installed: Q1. I am having a problem selecting nodes with XPATH expressions when an attribute values contain backslashes (\\)...
1
by: Tjerk Wolterink | last post by:
Hello all, I've written an XML file that looks a bit like this: <a> <space:b> content 1 </space:b> <b> content 2
12
by: Lawrence Oluyede | last post by:
I've some problems with filtering out a specific element by the following xml snippet (is part of a bigger xml document): <entry> <link...
1
by: Ramesh | last post by:
hi, I am selecting fields from three table for manupulating data and i want to display total number of records selected. But i am always getting...
3
by: larry mckay | last post by:
anyone have the code to select and listview item or row (subitems) after a doubleclick event from a listview. *** Sent via Developersdex...
3
by: Yoav Shapira | last post by:
Hi, I have a well-formed XHTML document that, among other content, has the following segment: <img src="uniqueUrl1" /> <p>some text</p>...
8
by: Jean-François Michaud | last post by:
Who in the name of #%@! thought this one out?? I noticed this behavior when trying to debug a problem I was having. I used this logical...
3
by: requeth | last post by:
Allo, I'm a little confused. I have an XSLT, in which my parser selects a node, but I want to just capture the first two characters to a...
7
by: Thomas Schmidt | last post by:
Hi all, I need an XPath which selects all nodes of a specific name which start with a text node, i.e. I want the expression to select: <x>...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.