1

I have a "milestone"-markup intertwingled with normal XML:

<root>
   <milestone type="opener" xml:id="m1" />
   text
      <milestone type="opener" xml:id="m2"/>
          text
      <milestone type="closer" ref="#m2"/>  
      text
      <node>
         text
      </node>
      ... 
   <milestone type="closer" ref="#m1"/>
</root>

and want to address the "parent"-milestone structure (i.e. milestone@xml:id='m1') to <node> using nothing than XPath.

Every milestone@xml:id corresponds with a milestone@ref as opener and closer of the milestone structure.

The "parent"-milestone-structure to the node would be identified by something similar to

node/preceding::milestone/concat('#',@xml:id) = node/following:milestone/@ref

This test relies on the context of the <node>. It could be implemented in XSLT with something like

<xsl:template match="node">
  <xsl:variable name="me" select="."/>
  <xsl:value-of select="./preceding::milestone[
       ./concat('#',@xml:id) =
       $me/following::milestone/@ref
    ][1]/@xml:id" />
</xsl:template>

But I cannot figure out how to do that with pure XPath.

Any suggestions?

  • By the way to make you above example work you have to remove the `./` before `concat('#',@xml:id)`. – hr_117 Jun 18 '13 at 09:52
  • I'm not fully sure what you want to do. Could you extend the question with an example for input (is the context the `` element?) and expected output? – Jens Erat Jun 18 '13 at 10:24
  • I've to prepare an import filter for an application being able to read only XPath in the input (what it does afterwards I don't know unfortunately). The application should create a "link" between the `` (i.e. it's (generated) ID) and the structure created by the milestones. In the given example `milestone[@xml:id='m1']` would be a correct output, `milestone[@xml:id='m2']` incorrect. – user2496459 Jun 19 '13 at 09:14

1 Answers1

0

Replace the variable $me with current().

hr_117
  • 9,589
  • 1
  • 18
  • 23