473,395 Members | 1,677 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 15123
> <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 (\\) in as part of its value: For example the...
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 -1 value, eventhough 1000 of records are selected....
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 http://www.developersdex.com *** Don't just participate...
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> <p>some other text</p> <p>some more text</p> <img...
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 expression and some XPATH in a specific sequence of...
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 variable. How would I do this? I know how to create the...
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> abcdefg <y>hijklmn</y> </x>
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.