0

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

如何使用 < 运算符获得所需的结果

任何帮助将不胜感激

4

1 回答 1

1

您可以尝试通过以下方式进行投射number()

/collection/movie[popularity[number(text()) < 8]]/format/text()
于 2015-09-21T11:56:17.767 回答