开发者

XPath Search relating to Attributes

I want to create an XPath query that returns cast members whose "job" is "Actor" and whose "order" is between "0" and "4" from the following XML. I'm finding it hard to create a query that does both.

<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"/>
开发者_Python百科    <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>


cast/person[@job="Actor" and @order >= 0 and @order <= 3] 

returns the four Simpsons you want.


You could use //cast/person[@job='Actor' and position()<3].


You should be able to combine your predicates //cast/person[@job='Actor' and @order>=0 and @order<=3]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜