包含函数如何在 xpath 中工作
How does contain function work in xpath
<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>
在上面的代码段中,我想获取描述元素包含子字符串的段的 title 属性 function.I 尝试使用包含 returns 布尔值并期望一个子字符串的函数参数的字符串。我尝试了一些 Xpaths 但没有成功,我知道答案是 collection/movie[contains(description,'bit')]/@title
由于只包含returns布尔值,上面是如何工作的case.Please澄清一下
具体跟contains()
没有关系,[...]
只是定义了一个predicate, with which to filter things. So tag[boolean-expression()]
will return to you exactly those tag
s for which boolean-expression()
returns true()
(or to be more precise: a value that can be converted to true()
).
<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>
在上面的代码段中,我想获取描述元素包含子字符串的段的 title 属性 function.I 尝试使用包含 returns 布尔值并期望一个子字符串的函数参数的字符串。我尝试了一些 Xpaths 但没有成功,我知道答案是 collection/movie[contains(description,'bit')]/@title
由于只包含returns布尔值,上面是如何工作的case.Please澄清一下
具体跟contains()
没有关系,[...]
只是定义了一个predicate, with which to filter things. So tag[boolean-expression()]
will return to you exactly those tag
s for which boolean-expression()
returns true()
(or to be more precise: a value that can be converted to true()
).