[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: How to extract data from an element and not from i

Subject: Re: How to extract data from an element and not from its children
From: "Andrew Welch" <andrew.j.welch@xxxxxxxxx>
Date: Wed, 6 Dec 2006 16:54:39 +0000
Re:  How to extract data from an element and not from i
On 12/6/06, CMS <cms@xxxxxxxxxxxxx> wrote:
Hi,

I can't find a way to solve this problem:

How do I extract the value of an element, without text in its children. E.g.
how do I extract from the next example the line 'This text is some test .'.

<text>This text is some test <emph>text</emph>.</text>

I think I am overlooking a simple function, but can't seem to find it.

The crucial thing to grasp here is that <text> contains the text node "This text is some test ", the element <emph> and then another text node "."

When you do value-of on <text> you get the text nodes of the element
and all its children concatenated together, so you would get the text
node child of <emph> - which isnt what you want.

When you do value-of select="text()" on <text> to only get the text
node children you get a sequence of two items - the two text nodes.
In 1.0 when you have a list of more than one item the first is used
and the rest discarded (to allow functions that expect a single item
to not fail if a list is supplied - XSLT 1.0 was designed to always
produce some output).

What all this means is that in 1.0 you can do either:

<xsl:for-each select="text()">
 <xsl:value-of select="."/>
</xsl:for-each>

or

<xsl:apply-templates select="text()"/>

Either technique will process each text node in turn.

In 2.0 all the items in the sequence get concatenated together using a
separator (if one's not supplied the default of a single space is
used), so a simple value-of select="text()" does the job.

cheers
andrew

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.