我想创建一个XPath
查询,该查询返回其“作业”为“Actor”并且其“order”在以下XML
中的“0”和“4”之间的演员。我发现很难创建一个同时执行这两个操作的查询。
<cast>
<person name="David Silverman" character="" job="Director" order="0"/>
<person name="James L. Brooks" character="" job="Author" order="0"/>
<person name="Dan Castellaneta" character="Homer J. Simpson" job="Actor" order="0"/>
<person name="Julie Kavner" character="Marge Simpson" job="Actor" order="1"/>
<person name="Nancy Cartwright" character="Bart Simpson" job="Actor" order="2"/>
<person name="Yeardley Smith" character="Lisa Simpson" job="Actor" order="3"/>
<person name="Dan Castellaneta" character="Krusty the Clown" job="Actor" order="4"/>
<person name="Hank Azaria" character="Moe Szyslak" job="Actor" order="5"/>
<person name="Dan Castellaneta" character="Apu Nahasapeemapetilon" job="Actor" order="6"/>
</cast>
答案 0 :(得分:3)
cast/person[@job="Actor" and @order >= 0 and @order <= 3]
返回你想要的四个辛普森。
答案 1 :(得分:0)
您可以使用//cast/person[@job='Actor' and position()<3]
。
答案 2 :(得分:0)
您应该能够合并谓词//cast/person[@job='Actor' and @order>=0 and @order<=3]