使用包含多个值的 XPath 查询

pro*_*son 1 php xml xpath simplexml

我需要一个 XPath,它将选择所有父节点一个具有至少包含值列表之一的属性的子节点。

示例 XML

<mynodes>
  <theParentNode>
    <theChildNode name="one two" />
  </theParentNode>
    <theParentNode>
    <theChildNode name="one all" />
  </theParentNode>
    <theParentNode>
    <theChildNode name="two" />
  </theParentNode>
    <theParentNode>
    <theChildNode name="all" />
  </theParentNode>
</mynodes>
Run Code Online (Sandbox Code Playgroud)

我想选择名称包含“一个”或“所有”(或任何其他组合)的所有节点。所以返回的 nodeList 是:

<theParentNode>
  <theChildNode name="one two" />
</theParentNode>
<theParentNode>
  <theChildNode name="one all" />
</theParentNode>
<theParentNode>
  <theChildNode name="all" />
</theParentNode>
Run Code Online (Sandbox Code Playgroud)

到目前为止,我的查询看起来像这样(注意我没有使用架构):

//theChildNode[contains(tokenize(@name, '\s'), "one")]

这将使我获得所有在其名称属性中包含“一”的供应商元素。但我不确定如何提供多个值来代替“一个”,然后是回到theParentNode. 如果可能的话,我总是可以在 php 中完成所有这些,但 id 而不是仅使用 XPath 来完成。

The*_*Don 5

有点多余,但这应该可以:

//theChildNode[contains(tokenize(@name, '\s'), "one") or contains(tokenize(@name, '\s'), "all")]
Run Code Online (Sandbox Code Playgroud)