根据兄弟姐妹值获取节点xpath查询

时间:2015-09-21 11:34:10

标签: xml xpath xpathquery

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

这给了我完美的结果,但当我使用&lt;时,它看起来并不令人印象深刻。运算符在xpath查询中给出了无效的xpath表达式

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

如何使用&lt;运算符以获得所需的结果

非常感谢任何帮助

1 个答案:

答案 0 :(得分:1)

您可以尝试通过jQuery(document).ready(function($) { $('#text-size').on('change', function(event) { event.preventDefault(); $textarea = $('#textarea'); size = $(this).val(); $textarea.attr('maxlength', size); $textarea.val($textarea.val().substr(0, size)); }); });

进行投射
number()