This XSLT stylesheet will pull the <fontspec> tags out
of the places where they are found (under pages) and
put them into a separate <fontspecs> section at the top.
----->-8-------
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output
method = "xml"
indent = "yes"
/>
<xsl:template match="/pdf2xml">
<pdf2xml>
<fontspecs>
<xsl:copy-of select="//fontspec"/>
</fontspecs>
<xsl:apply-templates/>
</pdf2xml>
</xsl:template>
<xsl:template match="fontspec"/>
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*" />
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
<xsl:template match="comment()|processing-instruction()">
<xsl:copy />
</xsl:template>
</xsl:stylesheet>