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

Re: How do I capture the text "around" a node?

Subject: Re: How do I capture the text "around" a node?
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 24 Sep 2002 15:50:23 +0100
xsl value of select translate
Hi Peter,

> Acutally, I should have added a bit more:
>
> <?xml version="1.0" ?>
> <book isbn="1234567890">
> Its title (<title>The Lord of the Rings</title>)
> is often misquoted!
> <author>J R R Tolkien</author>
> ...
> </book>
[snip]
> What I'm trying to do is actually capture the text using variables
> and substring-before and substring after, to get rid of the chars
> ().

Right. If you don't really care about retaining the structure (the
<title> and <author> elements) in the <book>, then the simplest thing
is just:

<xsl:template match="book">
  <xsl:value-of select="translate(., '()', '')" />
</xsl:template>

If you do want to keep the structure in some way, the best thing to do
is to use xsl:apply-templates and then use templates that remove ()s
from text nodes. So do:

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

If you want to make sure that you're only removing a ( at the end of a
text node that's immediately followed by a title element or at the
beginning of a text node that's immediately preceded by a title
element, then do something like:

<xsl:template match="text()[preceding-sibling::*[1][self::title] and
                            starts-with(., ')')]">
  <xsl:value-of select="substring-after(., ')')" />
</xsl:template>

<xsl:template match="text()[following-sibling::*[1][self::title] and
                            not(substring-after(., '('))]">
 <xsl:value-of select="substring-before(., '(')" />
</xsl:template>

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 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.