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

Re: Extracting text between nodes

Subject: Re: Extracting text between nodes
From: "Sam Byland" <shbyland@xxxxxxxxxxx>
Date: Wed, 13 Feb 2008 16:16:21 -0500
Re:  Extracting text between nodes
Wow. Kind of rare when I check this list and find an unanswered question :-)


<td><font><b>Title</b><br/>Some Text<i> and some more italic text</i><b> maybe even some more</b><a href="http://whatever.com">And an anchor</a></font></td>


I want to extract only the text between the first <br/> tag and the last <a> anchor tag, without the anchor's text but including all text in child elements such as the <i> and <b> - "Some Text and some more italic text maybe even some more"

How can I do it with xsl?

There are a couple ways you can do this -- the best way will depend on how your HTML will vary, or will it always be like your example. I would just use a template rule as follows:


<xsl:template match="a | b[position() = 1]"/>

A stylesheet with only the above template rule in it will output the following:

_____________

Some Text and some more italic text

maybe even some more
_____________


i.e. by default the text will be copied to the output, so I only specified those elements where you did *not* want the text copied to the output to "do nothing". In this case, any a element, and only the first b element, will not get their text copied to the output....


Hope that helps,

...sam

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.