[xsl] XPath Expression - find the first preceding-sibling that is a processing-instruction

Subject: [xsl] XPath Expression - find the first preceding-sibling that is a processing-instruction
From: "Craig Whisenhunt" <craig@xxxxxxxxxxxx>
Date: Wed, 1 Mar 2006 17:21:44 -0600
Altova XSLT 2.0 Engine (XMLSpy2006)

I want to look at preceding-siblings until I find a processing-instruction
and assign the value of that processing-instruction to a variable with
'select' so I can compare it to another variable later.

Sample XML:

<Body>
<Caption>
<Para><?Pub line="2" page="1" position="820"?>the cat in the hat.</Para>
</Caption>
<Clause>
<Para FirstLineIndent="7"><?Pub line="3" page="1" position="913"?>hello
world</Para>
</Clause>
<Para FirstLineIndent="7"><?Pub line="4" page="1" position="1010"?> SECTION
<HardSp/> <AutoNum/> Hi <HardSp/> <HardSp/> running around in circles <?Pub
line="5" page="1" position="1101"?> hard to follow.</Para>
</Body>

Stylesheet Excerpt:

<xsl:template match="text()|HardSp|AddedText|processing-instruction('Pub')"
mode="skillets">
<xsl:param name="currentPI"/>
  <xsl:if test="preceding-sibling::*[processing-instruction('Pub')]">
    <xsl:variable name="testPIvalue"
select="preceding-sibling::*[processing-instruction('Pub')]"/>
    <xsl:text>skillets!!!!</xsl:text>
  </xsl:if>
</xsl:template>

XPath expression in question:
preceding-sibling::*[processing-instruction('Pub')]

Not sure if my expression is correct for what I want to do, but it doesn't
'find' the preceding processing-instructions.

For example, when the context node is the text 'the cat in the hat', that
XPath expression does not find the processing-instruction just before it.
Similarly in the rest of the sample there, the expression does not find any
of the processing-instructions no matter what the context node.

Thanks,
-Craig

Current Thread