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

XPath 1.0: Use the attribute value of the current node's parent to find another matching node

我发现许多与此问题类似的 post,但没有任何内容可以回答此特定问题。我必须使用 XPath 1.0。我没有可用的 XSLT(或 XQuery 或其他任何东西),而且我不能使用 XPath 2.0。我从一个软件 (Arbortext Styler) 内部执行此 XPath,我可以在其中使用 XPath 1.0 来 select 来自其他节点的内容,但 XSLT 在此上下文中不可用。此外,我无法控制源代码的结构 XML。

当我在 <step> 的上下文中时,我需要能够匹配先前的 procedure/task/step,为此该步骤的 parent 过程与当前过程的 @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>.

的起始上下文完成

我怀疑我的问题的答案是无法做到,但我知道如果可以做到,这里就是找到答案的地方!预先感谢所有考虑这个问题的人。

这 post 是相似的,但搜索正在寻找起始上下文的 children:

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

有什么建议吗?

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