2

DOM_Document Xpathを使用して逆方向に検索する方法はありますか(ページの最後から上からではなく上に移動しますか?)そうであれば、これをどのように行いますか?

私はウェブサイトのかすり傷をしている。(以下にリンクされています)。 http://www.sturmfh.com/obit-display.jhtml?DB=update/obits/dbase&DO=display&ID=1189477693_24578

訃報の3つの段落だけを削りたい。だから私は最後から始めて上に移動するのが最も簡単だと思いました。

4

1 に答える 1

2

使用

(//p)[position() > count(//p) - 3]

pこれにより、XMLドキュメントの最後(最大3つ)の要素が選択されます。

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&amp;lname=Meier">Click</a>
   <a href="./obit-foldreq.jhtml?fname=Lyle&amp;lname=Meier">
      <img src="/images/email_condol.gif" border="0" alt="View" align="top"/>
   </a>
   <a href="./obit-foldreq.jhtml?fname=Lyle&amp;lname=Meier">here</a>
</p>
于 2011-12-21T20:22:25.627 に答える