我发现了许多与此问题类似的帖子,但没有任何内容可以回答这个特定问题。我必须使用 XPath 1.0。我没有可用的 XSLT(或 XQuery 或其他任何东西),也无法使用 XPath 2.0。我从一个软件 (Arbortext Styler) 内部执行此 XPath,我可以在其中使用 XPath 1.0 从其他节点选择内容,但 XSLT 在此上下文中不可用。此外,我无法控制源 XML 的结构。
当我在 的上下文中时<step>
,我需要能够匹配上一个过程/任务/步骤,该步骤的父过程匹配当前过程的@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 of Matches another Node
这也很有趣,但我的属性值不是 ID:Xpath: find an element value from a match of id attribute to id anchor
有什么建议么?