首页 文章

XPath 1.0:使用当前节点父节点的属性值来查找另一个匹配节点

提问于
浏览
2

我在这个问题上找到了许多相似的帖子,但没有任何内容可以回答这个问题 . 我必须使用XPath 1.0 . 我没有可用的XSLT(或XQuery或其他任何东西),我不能使用XPath 2.0 . 我正在从一个软件(Arbortext Styler)中执行这个XPath,我可以使用XPath 1.0从其他节点中选择内容,但在这种情况下XSLT不可用 . 此外,我无法控制源XML的结构 .

当我在 <step> 的上下文中时,我需要能够匹配前一个过程/任务/步骤,该步骤's parent procedure matches the current procedure' s @ref和@seq并且字母"A"为@conf的值 .

<document>
  <topic>
    <procedure ref="056" seq="01" conf="A">
      <task>
        <step>1. Blah Blah (056-01-A)</step>
      </task>
    </procedure>
    <procedure ref="057" seq="02" conf="A">
      <task>
        <step>2. Blah blah (057-02-A)</step>
      </task>
    </procedure>
    <procedure ref="057" seq="02" conf="B">
        <task>
            <step>2. Blah blah (057-02-B)</step>
        </task>
    </procedure>
    <procedure ref="057" seq="03" conf="A">
        <task>
            <step>3. Blah blah (057-02-A)</step>
        </task>
    </procedure>
  </topic>
</document>

我需要的是这样的东西,但没有current()函数,软件应用程序不支持:

//procedure[@ref=current()/ancestor::procedure/@ref and @seq=current()/ancestor::procedure/@seq and @conf='A']/task/step

或类似的东西,但没有for in return语句:

for $ref in ancestor::procedure/@ref, $seq in ancestor::procedure/@seq return //topic/procedure[@ref=$ref and @seq=$seq and @conf='A']/task/step/text()

有没有人有任何关于如何使用XPath 1.0完成这项工作的建议?请注意,程序的位置不能硬编码 . 重复的refs可以多次出现在任何位置 . 此外,要求使用 <step> 的起始上下文完成此匹配 .

我怀疑我的问题的答案是它无法完成,但我知道如果可以做到,这就是找到答案的地方!提前感谢所有考虑这个问题的人 .

这篇文章是类似的,但搜索正在寻找起始背景的孩子:Xpath Getting All Nodes that Have an Attribute that Matches Another Node

这也很有趣,但我的属性值不是ID:Xpath: find an element value from a match of id attribute to id anchor

有什么建议?

1 回答

  • 0

    正如Tomalak和Honza Hejzl所建议的那样,XPath 1.0无法做到这一点 . 感谢您的反馈 .

相关问题