XPath 1.0:使用当前节点的父节点的属性值来查找另一个匹配的节点 [英] XPath 1.0: Use the attribute value of the current node's parent to find another matching node

查看:124
本文介绍了XPath 1.0:使用当前节点的父节点的属性值来查找另一个匹配的节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现许多与此问题类似的帖子,但没有任何答案可以回答这个特定问题.我必须使用XPath 1.0.我没有可用的XSLT(或XQuery或其他任何东西),并且我不能使用XPath 2.0.我正在从一个软件(Arbortext Styler)内部执行此XPath,可以在其中使用XPath 1.0从其他节点中选择内容,但是XSLT在此上下文中不可用.另外,我无法控制源XML的结构.

I have found many similar posts to this question, but nothing that answers this specific question. I must use XPath 1.0. I do not have XSLT (or XQuery or anything else) available to me, and I cannot use XPath 2.0. I am executing this XPath from inside a piece of software (Arbortext Styler), in which I can use XPath 1.0 to select content from other nodes, but XSLT is not available in this context. Also, I have no control over the structure of the source XML.

<step>上下文中,我需要能够匹配先前的过程/任务/步骤,该步骤的父过程与该过程的父过程与当前过程的@ref和@seq匹配,并且字母为"A"作为@conf的值.

When I am in the context of <step>, I need to be able to match a previous procedure/task/step for which that step's parent procedure matches the current procedure's @ref and @seq and has the letter "A" as the value for @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()函数,软件应用程序不支持该函数:

What I need is something like this, but without the current() function, which is not supported by the software application:

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

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

Or something like this, but without the for in return statement:

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如何实现这一目标,是否有人有任何建议?请注意,该过程的位置无法进行硬编码.重复的引用可以在任意位置多次出现.另外,还要求此匹配必须以<step>的起始上下文来完成.

Does anyone have any suggestions for how this could be accomplished purely with XPath 1.0? Please note that the position of the procedure cannot be hardcoded. The duplicate refs can occur multiple times and in any position. Also, it is a requirement that this match be done with a starting context of <step>.

我怀疑我的问题的答案是无法解决,但我确实知道,如果可以解决,这是寻找答案的地方!预先感谢所有考虑此问题的人.

I suspect the answer to my question is that it can't be done, but I do know that if it can be done, this is the place to find the answer! Thanks, in advance, to all of you who consider this question.

此帖子类似,但搜索是在寻找具有起始上下文的孩子:

This post was similar, but the search was looking for children of starting context: Xpath Getting All Nodes that Have an Attribute that Matches Another Node

这也很有趣,但是我的属性值不是ID:

This was also interesting, but my attribute value is not an ID: Xpath: find an element value from a match of id attribute to id anchor

有什么建议吗?

推荐答案

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

As suggested by both Tomalak and Honza Hejzl, this cannot be done with XPath 1.0. Thanks for the feedback.

这篇关于XPath 1.0:使用当前节点的父节点的属性值来查找另一个匹配的节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆