Get node based on siblings value xpath query

时间秒杀一切 提交于 2019-12-12 03:17:46

问题


I want to get all the format nodes text in which its sibling node popularity is less than 8

<collection shelf="Classics">
<movie title="The Enemy" shelf="A">
   <type>War, Thriller</type>
   <format>DVD</format>
   <year>2001</year>
   <rating>PG</rating>
   <popularity>10</popularity>
   <description>Talk about a war</description>
</movie>
<movie title="Transformers" shelf="B">
   <type>Science Fiction</type>
   <format>DVD</format>
   <year>1980</year>
   <rating>R</rating>
   <popularity>7</popularity>
   <description>Science Fiction</description>
</movie>
   <movie title="Trigun" shelf="B">
   <type>Action</type>
   <format>DVD</format>
   <episodes>4</episodes>
   <rating>PG</rating>
   <popularity>10</popularity>
   <description>Quite a bit of action!</description>
</movie>
<movie title="Ishtar" shelf="A">
   <type>Comedy</type>
   <format>VHS</format>
   <rating>PG</rating>
   <popularity>2</popularity>
   <description>Boring</description>
</movie>
</collection>

so far i am using the query is

/collection/movie[popularity[text() != '8' and text()!='9' and text()!=10]]/format/text()

which gives me perfect results but it doesn't looks much impressive ,when i use < operator in xpath query its gives invalid xpath expression

/collection/movie[popularity[text() &lt; 8]]/format/text()

how to use < operator to get the desired results

Any help will be greatly appreciated


回答1:


you can try casting via number():

/collection/movie[popularity[number(text()) < 8]]/format/text()


来源:https://stackoverflow.com/questions/32694186/get-node-based-on-siblings-value-xpath-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!