根据siblings值获取节点xpath查询

Get node based on siblings value xpath query

我想获取其兄弟节点流行度小于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 查询中使用 < 运算符时,它给出了无效的 xpath 表达式

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

如何使用 < 运算符获得想要的结果

任何帮助将不胜感激

您可以尝试通过 number() 投射:

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