小编Kev*_*gel的帖子

编写XPath查询以根据属性和内容匹配元素

我有一些像这样的XML:

<topics>
  <topic id="50"/>
  <topic id="51"/>
  <topic id="52"/>
</topics>

<discussions>
  <discussion type="foo">talked about T50 as Discussion 1000</discussion>
  <discussion type="bar">Food is yummy!</discussion>
  <discussion type="foo">talked about T52 as Discussion 1050</discussion>
</discussions>
Run Code Online (Sandbox Code Playgroud)

给定一个特定的主题ID($topicID),我想做以下事情:

  • 设计一个XPath表达式,如果有包含该文本的<discussion>with type="foo",则为true T$topicID as Discussion <corresponding-discussion-id>.

  • 设计一个XPath表达式,给定$topicID它将提取文本Discussion <corresponding-discussion-id>.

这可能吗?


更新:

对于第一个,我想我需要这样的东西:

exists(
 //discussions/discussion[
  @type="foo" and
  contains(text(), concat($topicId, ??? ))  <-- What goes here? I think we need
 ]                                           some kind of matches(...) around the
)                                            concat(), too.
Run Code Online (Sandbox Code Playgroud)

string xslt xpath expression

4
推荐指数
1
解决办法
1522
查看次数

标签 统计

expression ×1

string ×1

xpath ×1

xslt ×1