使用:
//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>