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.
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>
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
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()
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
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
Any suggestions?
As suggested by both Tomalak and Honza Hejzl, this cannot be done with XPath 1.0. Thanks for the feedback.