Reputation: 11915
I'm trying to get the following text
Divided into:
Bonaire, Sint Eustatius and Saba (BQ, BES, 535)
Curaçao (CW, CUW, 531)
Sint Maarten (Dutch part) (SX, SXM, 534)
out of this source (excerpt):
<td>
Divided into:<br />
<a href="/wiki/Caribbean_Netherlands" title="Caribbean Netherlands">Bonaire, Sint Eustatius and Saba</a> (<tt>BQ</tt>, <tt>BES</tt>, <tt>535</tt>) <sup id="cite_ref-7" class="reference">
<a href="#cite_note-7">
<span>[</span>note 4<span>]</span>
</a>
</sup><br />
<a href="/wiki/Cura%C3%A7ao" title="Curaçao">Curaçao</a> (<tt>CW</tt>, <tt>CUW</tt>, <tt>531</tt>)<br />
<a href="/wiki/Sint_Maarten" title="Sint Maarten">Sint Maarten (Dutch part)</a> (<tt>SX</tt>, <tt>SXM</tt>, <tt>534</tt>)
</td>
This is easily done with <xsl:value select="td[4]"/>
(it's the 4th td element, and I'm looping over the surrounded tr
s).
But I want to exclude the text [note 4]
, so every a
that has span
children.
I tried td[4]/node()[not(descendant::span)]
, but it only left Divided into:
. td[4][not(//span)]
gives always empty strings.
Upvotes: 0
Views: 185
Reputation: 611
when you match td[4]/node()[not(descendant::span)]
you're matching the forth td that doesn't have a span descendant. Since your td[4] does have a span descendant,you're getting empty results.
What you need is is a template to match the td[4] descendant nodes that does text output:
<xsl:template match="td[4]/node()"> ... <xsl:template> <!-- match descendant nodes of td[4] -->
and another template to specifically catch the span node:
<xsl:template match="span | text()[preceding-sibling::span] | text()[following-sibling::span]"/>
Upvotes: 1