【问题标题】:Get node based on siblings value xpath query基于兄弟值xpath查询获取节点
【发布时间】:2015-12-18 02:12:36
【问题描述】:

我想获取其兄弟节点流行度小于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>

到目前为止,我使用的查询是

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

这给了我完美的结果,但它看起来并不令人印象深刻,当我在 xpath 查询中使用

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

如何使用

任何帮助将不胜感激

【问题讨论】:

    标签: xml xpath xpathquery


    【解决方案1】:

    你可以尝试通过number()进行投射:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多