$vStart
この XPath 式は、ノードとの間のすべての (兄弟) ノードを選択します$vEnd
。
$vStart/following-sibling::node()
[count(.|$vEnd/preceding-sibling::node())
=
count($vEnd/preceding-sibling::node())
]
特定のケースで使用する完全な XPath 式を取得するには、次のように置き換えます$vStart
。
/*/b[. = 'Content Title']
次のように置き換え$vEnd
ます。
/*/a[@href = 'javascript:print()']
置換後の最終的な XPath 式は次のとおりです。
/*/b[. = 'Content Title']/following-sibling::node()
[count(.|/*/a[@href = 'javascript:print()']/preceding-sibling::node())
=
count(/*/a[@href = 'javascript:print()']/preceding-sibling::node())
]
説明:
$ns1
これは、2 つのノードセットとの交点に対する Kayess の式の単純な帰結です$ns2
。
$ns1[count(.|$ns2) = count($ns2)]
この場合、ノード$vStart
との間のすべてのノードのセットは、 の後続のすべての兄弟と の先行するすべて$vEnd
の兄弟の 2 つのノードセットの共通部分です。$vStart
$vEnd
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:variable name="vStart" select="/*/b[. = 'Content Title']"/>
<xsl:variable name="vEnd" select="/*/a[@href = 'javascript:print()']"/>
<xsl:template match="/">
<xsl:copy-of select=
"$vStart/following-sibling::node()
[count(.|$vEnd/preceding-sibling::node())
=
count($vEnd/preceding-sibling::node())
]
"/>
==============
<xsl:copy-of select=
"/*/b[. = 'Content Title']/following-sibling::node()
[count(.|/*/a[@href = 'javascript:print()']/preceding-sibling::node())
=
count(/*/a[@href = 'javascript:print()']/preceding-sibling::node())
]
"/>
</xsl:template>
</xsl:stylesheet>
この変換が提供された XML ドキュメントに適用されると(整形式の XML ドキュメントに変換されます):
<div class="post-body entry-content">
<a href="http://www.photourl">
<img alt="Photo title" height="333" src="http://photourl.com" width="500"/>
</a>
<br />
<br />
<div style="text-align: justify;">
Some text</div>
<b>More text</b>
<br />
<b>More text</b>
<br />
<br />
<ul>
<li>Numered item</li>
<li>Numered item</li>
<li>Numered item</li>
</ul>
<br />
<b>Content Title</b>
<br />
Some text
<br />
<br />
Some text(with links and images)
<br />
Some text(with links and images)
<br />
Some text(with links and images)
<br />
<br />
<br />
<a href="javascript:print()">
<img src="http://url.com/photo.jpg"/>
</a>
<div style="clear: both;"></div>
</div>
2 つの XPath 式 (変数参照がある場合とない場合) が評価され、それぞれの場合に選択されたノードが適切に区切られて出力にコピーされます。
<br/>
Some text
<br/>
<br/>
Some text(with links and images)
<br/>
Some text(with links and images)
<br/>
Some text(with links and images)
<br/>
<br/>
<br/>
==============
<br/>
Some text
<br/>
<br/>
Some text(with links and images)
<br/>
Some text(with links and images)
<br/>
Some text(with links and images)
<br/>
<br/>
<br/>