我有以下XML文件:如何使用XPATH獲取此列表中的所有非排除項目?
<items>
<item>
<name>Suede Shoe</name>
<category>Footwear</category>
<price>£90.00</price>
<tags>
<footwear />
<shoes />
</tags>
</item>
<item>
<name>Leather Shoe</name>
<category>footwear</category>
<price>£90.00</price>
<tags>
<footwear />
</tags>
</item>
<item>
<name>Canvas Shoe</name>
<category>Footwear</category>
<price>£90.00</price>
<tags>
<footwear exclude="true"/>
<shoes/>
</tags>
</item>
<item>
<name>Toecap Shoe</name>
<category>Footwear</category>
<price>£90.00</price>
<tags>
<footwear exclude="true"/>
</tags>
</item>
</items>
我想選擇所有包含我的選擇標籤中的一個項目,但如果標籤被排除在外不帶回來的結果。
例子:
標籤:鞋類
返回:1,2
標籤:鞋
返回1,3
標籤:鞋類|鞋
返回1,2,3
請幫忙嗎?
包括「排除」,要求此XPath是工作之前:
//tags[implode('|', $tags)]/parent::item
標籤「鞋類」,即不排除。
目前還不清楚你到底要XPath表達式返回 - 「1,2」是什麼意思? – 2011-02-03 14:56:01