有没有办法,当使用 DOM_Document Xpath 反向搜索(从页面末尾向上移动而不是从上向下移动?)如果是这样,我会怎么做?
我正在浏览一个网站。(下面链接)。 http://www.sturmfh.com/obit-display.jhtml?DB=update/obits/dbase&DO=display&ID=1189477693_24578
我只想刮掉3个讣告段落。所以我认为从最后开始向上移动是最容易的。
有没有办法,当使用 DOM_Document Xpath 反向搜索(从页面末尾向上移动而不是从上向下移动?)如果是这样,我会怎么做?
我正在浏览一个网站。(下面链接)。 http://www.sturmfh.com/obit-display.jhtml?DB=update/obits/dbase&DO=display&ID=1189477693_24578
我只想刮掉3个讣告段落。所以我认为从最后开始向上移动是最容易的。
使用:
(//p)[position() > count(//p) - 3]
这将选择 XML 文档中的最后一个(最多三个)p
元素。
基于 XSLT 的验证:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy-of select="(//p)[position() > count(//p) - 3]"/>
</xsl:template>
</xsl:stylesheet>
当应用于问题中引用的文档时,此转换将评估 XPath 表达式并输出所选p
元素。
结果是:
<p>
If you would like to share your thoughts and memories,<br/> we will deliver your message to the family.<br/>
<a href="mailto:staff@sturmfh.com?Subject=For%20the%20Family%20of%20Lyle%20Meier">Click</a>
<a href="mailto:staff@sturmfh.com?Subject=For%20the%20Family%20of%20Lyle%20Meier">
<img src="/images/email_condol.gif" alt="Logo" border="0" align="middle"/>
</a>
<a href="mailto:staff@sturmfh.com?Subject=For%20the%20Family%20of%20Lyle%20Meier">here</a>.
</p>
<p>To Request a Tribute Folder
<br/>
<a href="./obit-foldreq.jhtml?fname=Lyle&lname=Meier">Click</a>
<a href="./obit-foldreq.jhtml?fname=Lyle&lname=Meier">
<img src="/images/email_condol.gif" border="0" alt="View" align="top"/>
</a>
<a href="./obit-foldreq.jhtml?fname=Lyle&lname=Meier">here</a>
</p>