属性値に基づいて、XML 要素をそれぞれの場所に移動する必要があります。id の属性値が一致する場合、要素をそれぞれの場所に<m:footnote>
移動する必要があります。<m:endnote>
サンプル XML:
<m:chapter xmlns:m="http://www.w3.org/1998/Math/MathML">
<m:front>
<m:p>This is <m:footnote id="1"/>para</m:p>
</m:front>
<m:body>
<m:p>This is <m:footnote id="2"/>para</m:p>
<m:p>This is <m:footnote id="3"/>para</m:p>
<m:p>This is <m:footnote id="4"/>para</m:p>
</m:body>
<m:endnote>
<m:footnote id="1">This is footnote 1</m:footnote>
<m:footnote id="2">This is footnote 2</m:footnote>
<m:footnote id="3">This is footnote 3</m:footnote>
<m:footnote id="4">This is footnote 4</m:footnote>
</m:endnote>
</m:chapter>
必要な出力:
<?xml version='1.0' encoding='UTF-8' ?>
<m:chapter xmlns:m="http://www.w3.org/1998/Math/MathML">
<m:front>
<m:p>This is <m:footnote id="1">This is footnote 1</m:footnote>para</m:p>
</m:front>
<m:body>
<m:p>This is <m:footnote id="2">This is footnote 2</m:footnote>para</m:p>
<m:p>This is <m:footnote id="3">This is footnote 3</m:footnote>para</m:p>
<m:p>This is <m:footnote id="4">This is footnote 4</m:footnote>>para</m:p>
</m:body>
</m:chapter>
XSLT が試した:
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:m="http://www.w3.org/1998/Math/MathML" exclude-result-prefixes="m">
<xsl:output method="xml" encoding="UTF-8" indent="no"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="m:chapter">
<xsl:copy>
<xsl:apply-templates/>
<xsl:for-each select="child::*/descendant::m:footnote">
<xsl:choose>
<xsl:when test="not(parent::m:endnote)">
<xsl:if test="string(self::m:footnote/@id) = string('ancestor::m:chapter/m:endnote/m:footnote/@id')">
<xsl:copy-of select="m:chapter/m:endnote/m:footnote"/>
</xsl:if>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:copy>
</xsl:template>
<xsl:template match="m:endnote"></xsl:template>
</xsl:stylesheet>