[xsl] questions about preceding::processing-instruction

Subject: [xsl] questions about preceding::processing-instruction
From: "Erik Zander erik.zander@xxxxxxxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 10 Apr 2017 13:12:00 -0000
Hi All!

I have an optimization problem concerning preceding::processing-instruction.

First some background in my xml I have processing instructions like <?anchor
xml:id="orgPage.7"/?> representing the start of a page.
And I have a template that matches on text().

In the template matching on text() I want to know the page number.

To get this I have in the text template declared a variable as
<xsl:variable name="currentPage"
select="substring-before(substring-after(((./preceding::processing-instructio
n('anchor'))[last()]), 'Page.'), '&quot;')"/>

Which works (although I don't see why as I had the understanding that
preceding:: returned in reverse document order) but it takes up a great deal
of the processing time.

So my questions are:
Is there a better (faster/smarter) way to get the page from the processing
instruction.

And is it the expected behavior that calling
preceding:processing-instruction() gives me
<?anchor xml:id="orgPage.1"/?>
<?anchor xml:id="orgPage.2"/?>
<?anchor xml:id="orgPage.3"/?>
<?anchor xml:id="orgPage.4"/?>
I have this behavior in both Saxon 9.6.0.7 and Marklogic.

Regards
Erik Zander

Current Thread