[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?
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|