The following transform will give the desired output.
Note that it makes a few assumptions about how the content is structured. In particular, how do you know when a p
is a footnote? It is structurally the same as other paragraphs. The code below uses the identifier naming scheme, which may or may not be consistent throughout your real input.
The same applies when omitting the footnote back-reference itself when copying the footnote content. The following code uses a simple approach of copying the anchor's sibling text, which may also be too simplistic for your real data.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="xhtml">
<xsl:key name="fn" match="xhtml:a" use="@name" />
<!-- Copy template with namespace stripped -->
<xsl:template match="*">
<xsl:element name="{name()}">
<xsl:apply-templates select="node()|@*" />
</xsl:element>
</xsl:template>
<!-- Omit footnote content instead of reference -->
<xsl:template match="xhtml:a[key('fn', substring-after(@href, '#'))]">
<note>
<xsl:copy-of select="key('fn', substring-after(@href, '#'))/../text()"/>
</note>
</xsl:template>
<!-- Hack to omit the footnotes themselves -->
<xsl:template match="xhtml:*[xhtml:a[contains(@href, '_ftnref')]]" />
</xsl:stylesheet>