1
我需要提供一个查询,该查询可以提供没有任何项目的类型的产品如果某个项目是服装类型,并且没有服装项目出现在交易清单中,我需要显示它。XPath查询:查找具有与属性相同的ID列表的元素
这是我的XML文件(超级加拿大岬道歉):
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE store [
<!ELEMENT store (product*, transaction*)>
<!ATTLIST store name CDATA #REQUIRED >
<!ELEMENT product EMPTY>
<!ATTLIST product
name ID #REQUIRED
type CDATA #REQUIRED
price CDATA #REQUIRED
>
<!ELEMENT transaction EMPTY>
<!ATTLIST transaction
products IDREFS #REQUIRED
sumPrice CDATA #REQUIRED
>
]>
<store name="Gordons">
<product name="beaverCoat" type="clothing" price="100"/>
<product name="hockeyStick" type="equipment" price="30"/>
<product name="hockeyPuck" type="equipment" price="5"/>
<product name="icePick" type="equipment" price="40"/>
<product name="mooseMeat" type="food" price="350"/>
<product name="salmon" type="food" price="15"/>
<transaction products="salmon mooseMeat" sumPrice="365"/>
<transaction products="hockeyPuck hockeyStick" sumPrice="35"/>
<transaction products="hockeyStick mooseMeat" sumPrice="380"/>
<transaction products="salmon mooseMeat" sumPrice="300"/>
<transaction products="hockeyStick hockeyStick hockeyStick" sumPrice="30"/>
</store>
所需的输出
<transaction products="salmon mooseMeat" sumPrice="365"/>
<transaction products="salmon mooseMeat" sumPrice="300"/>
,因为他们具有相同的产品作为另一交易交易(eachother)
MY ATTEMPT 我玩过一些查询,但我无法正确理解。这是我已经得到最接近:
这是我已经试过:
//transaction[id(@products) = //transaction/@products]
看起来这应该工作 - 发现其产品符合所有其他交易产品属性的所有事务。然而,它没有获得任何奖项。
它的工作原理!谢谢!但是,有没有办法只返回不同的元素?当'sumPrice'是相同的,它不应该同时打印。 – CodyBugstein
你知道你的XPath引擎是否可以使用XPath 2.0吗?我可以想办法在XPath 2.0中排除重复项,但不是在1.0中。 – JLRishe
nope它不能:( – CodyBugstein