我有一個「里程碑」 -markup與正常XML intertwingled:查找有對應於使用XPath後面的節點的先前節點僅
<root>
<milestone type="opener" xml:id="m1" />
text
<milestone type="opener" xml:id="m2"/>
text
<milestone type="closer" ref="#m2"/>
text
<node>
text
</node>
...
<milestone type="closer" ref="#m1"/>
</root>
和要講到「父」 -milestone結構(即[email protected]:id='m1'
)到<node>
使用什麼比XPath。
每個[email protected]:id
對應一個[email protected]
作爲里程碑結構的開場和接近。
「父」 -milestone結構到節點將由類似的東西被標識爲
node/preceding::milestone/concat('#',@xml:id) = node/following:milestone/@ref
該測試依賴於<node>
的上下文。它可以在XSLT來實現的東西,如
<xsl:template match="node">
<xsl:variable name="me" select="."/>
<xsl:value-of select="./preceding::milestone[
./concat('#',@xml:id) =
$me/following::milestone/@ref
][1]/@xml:id" />
</xsl:template>
但我無法弄清楚如何做到這一點用純XPath的。
有什麼建議嗎?
順便說一句,讓你上面的例子工作,你必須刪除'。/'之前'concat('#',@ xml:id)''。 –
我不完全確定你想要做什麼。你能用一個輸入的例子來擴展這個問題嗎(是''元素的上下文?)和期望的輸出嗎? –
我必須爲應用程序準備一個導入過濾器,以便在輸入中只能讀取XPath(之後我不知道該怎麼辦)。應用程序應該在''(即它的(生成的)ID)和由里程碑創建的結構之間創建一個「鏈接」。在給定示例中,里程碑[@xml:id ='m1']'是正確的輸出,'里程碑[@xml:id ='m2']'不正確。 – user2496459