【问题标题】:How does contain function work in xpath包含函数如何在 xpath 中工作
【发布时间】:2018-12-30 16:46:27
【问题描述】:
<collection>
<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>

在上面的代码段中,我想获取描述元素包含子字符串函数的段的标题属性。我尝试使用包含返回布尔值并期望参数为字符串的函数。我尝试了一些 Xpaths 的东西,但效果很好,我知道答案是 collection/movie[contains(description,'bit')]/@title

由于 contains 只返回布尔值,在上述情况下它是如何工作的。请澄清

【问题讨论】:

    标签: xpath contains


    【解决方案1】:

    它与contains() 无关,具体来说,[...] 只是定义了一个predicate,用于过滤事物。所以tag[boolean-expression()] 将返回给你的tags 正是boolean-expression() 返回true()(或更准确地说:a value that can be converted to true())的那些tags。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-12-28
      • 1970-01-01
      • 2010-12-22
      • 2014-02-19
      • 2013-08-13
      • 2021-04-05
      相关资源
      最近更新 更多