我有這個源XML樹:XPath表達式來排除一些子節點
<?xml version="1.0" encoding="UTF-8"?>
<root>
<foo>
<bar>
<baz>
<item>
<methods>
<item>
<id>1</id>
</item>
</methods>
<id>1</id>
</item>
<item>
<methods>
<item>
<id>19</id>
</item>
</methods>
<id>2</id>
</item>
</baz>
</bar>
</foo>
<bar_method>
<root>
<bla id="1">
<methods>
<method id="1">
<calc md="ck" />
<tm m="14" />
<price_list>
<price mse="0">
<ins re="0" />
</price>
</price_list>
</method>
<method id="2">
<calc md="qck" />
<tm m="4" />
<price_list>
<price mse="1">
<ins re="0" />
</price>
</price_list>
</method>
</methods>
</bla>
<bla id="2">
<methods>
<method id="19">
<calc md="dd" />
<tm m="3" />
<price_list>
<price mse="01">
<ins re="0" />
</price>
</price_list>
</method>
</methods>
</bla>
</root>
</bar_method>
</root>
現在我需要使用XPath把這個樹的片段變量。片段應該是這樣的:
<bla id="1">
<methods>
<method id="1">
<calc md="ck" />
<tm m="14" />
<price_list>
<price mse="0">
<ins re="0" />
</price>
</price_list>
</method>
</methods>
</bla>
<bla id="2">
<methods>
<method id="19">
<calc md="dd" />
<tm m="3" />
<price_list>
<price mse="01">
<ins re="0" />
</price>
</price_list>
</method>
</methods>
</bla>
這些都是不含method
節點,id
屬性bla
節點這/root/foo/bar/baz/item/methods/item/id
失蹤。我用下面的表達,但它與重複選擇的所有節點:
<xsl:variable name="meth" select="/root/bar_method/root//*[not(name() = 'method' and count(/root/foo/bar/baz//methods/item[id = @id]) = 0)]" />
爲什麼你需要把片段放在一個變量中。您希望從XSL獲得什麼輸出?像你一樣需要模板給我。 –
我只是想知道是否有可能。 –
看起來你想要所有'bla'元素,並且只需要在它們中的第一個'methods/method'元素。是對的嗎?你不能在單個XPath表達式中這樣做,因爲你只能限制被選中的元素 - 你也不能過濾掉它們的一些後代。 – Borodin