It's hard to tell without doing a time consuming analysis, but try changing this xsl:if
(in match="footnote" mode="footnote"
):
<xsl:if test="preceding::node()[page[1]]">
<xsl:variable name="op"><</xsl:variable>
<xsl:variable name="apos">'</xsl:variable>
<xsl:variable name="cl">></xsl:variable>
<xsl:value-of select="concat($op,'?pb label=',$apos,preceding::page[1]/@num,$apos,'?',$cl)"/>
</xsl:if>
To this:
<xsl:if test="(preceding::page|preceding::footnote)[last()][self::page]">
<xsl:processing-instruction name="pb" select="concat('label=''',preceding::page[1]/@num,'''?')"/>
</xsl:if>
Kinda strange that you're trying to output XML processing instructions when your output method is HTML (which would have SGML processing instructions).