xsl-list
[Top] [All Lists]

Re: [xsl] Extracting text between nodes

2008-02-13 14:17:05
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



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--