Finding a Same-Level Predecessor in XML using XPath
I have an XML Document I am attempting to get some data from. I have a known quantity, and on the same level and unknown quantity. So the format looks like this:
<header>Unknown Item</header> <title>Known Item</title>
This is the very simplified version. Now I may have any number of this format in succession, but what I want to be able to do is given the known item, which gives me the ability to navigate to that node, use a built-in way to get the nearest same-level predecessor. Each pair of known and unknown items are tied together in the domain space, but not in the XML.
If it's relevant, this is being done in Scala using Saxon as my parser, working over cleaned HTML. It seems to be that this is a fairly abstract problem, however.
It sounds as if you want to access the preceding-sibling::header e.g.
<xsl:template match="title"> <xsl:variable name="header" select="preceding-sibling::header"/> </xsl:template>