使用:
//node()[self::h4 or self::text()]
[normalize-space() = 'Replaces the following numbers:']
/following-sibling::*[1][self::table]
XSLT ベースの検証:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
<xsl:copy-of select=
"//node()[self::h4 or self::text()]
[normalize-space() = 'Replaces the following numbers:']
/following-sibling::*[1][self::table]
"/>
</xsl:template>
</xsl:stylesheet>
この変換が提供されたドキュメント(整形式の XML ドキュメントになるように修正) に適用されると、次のようになります。
<div id="details">
Here is some text without a p tag. Oh, let's write some more.
<br />
<br />
And some more.
<table id="non-unique">
...
</table>
Replaces the following numbers:
<table id="non-unique">
... good stuff in here
</table>
</div>
XPath 式が評価され、選択されたノードが出力にコピーされます。
<table id="non-unique">
... good stuff in here
</table>
この XML ドキュメントに同じ変換 (XPath 式) を適用すると、次のようになります。
<div id="details">
Here is some text without a p tag. Oh, let's write some more.
<br />
<br />
And some more.
<table id="non-unique">
...
</table>
<h4>Replaces the following numbers:</h4>
<table id="non-unique">
... good stuff in here
</table>
</div>
もう一度、必要な要素が選択されて出力されます。
<table id="non-unique">
... good stuff in here
</table>