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

Re: How to select text only for element with mixed content?

Subject: Re: How to select text only for element with mixed content?
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Wed, 28 Jun 2000 22:19:22 +0100
xsl apply templates select text
>Is there a way of getting only the text for
>the current tag without having to write a
>seperate template?

Sure.  The XPaths that you use in select expressions can pinpoint
particular types of nodes, and one of those types is text, through text().
So, you can select only the text() children of Tag1 in just the same way as
you would select only the Tag2 children of Tag1, and apply templates to them:

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

This relies on using the built-in template to give the value of the text.
You can use xsl:value-of if you prefer instead.  One thing to note if you
do that, though, is that all the whitespace between the child elements
counts as text too.  If you do something like:

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

you get the confusing result that you seem to get no output.  In fact, you
are getting output, but you are only getting the value of the first piece
of text, which is whitespace.  If you want to get the value of text that
isn't just whitespace, you can use a predicate to choose only those bits of
text that aren't made up solely of whitespace:

<xsl:value-of select="text()[normalize-space(.) != '']" />

I hope this helps,

Jeni

Dr Jeni Tennison
Epistemics Ltd * Strelley Hall * Nottingham * NG8 6PE
tel: 0115 906 1301 * fax: 0115 906 1304 * email: jeni.tennison@xxxxxxxxxxxxxxxx


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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-2013 All Rights Reserved.