以下の XML で説明するように、スペースを削除して、特定の子要素 (つまり、「数学」) に対してのみ要素間に戻ります。やってみ<xsl:strip-space elements="m:math"/>
ました。ただし、すべての要素のスペースが削除されます。<style>
要素の後のスペースと要素の前のスペースを保持する必要があり<b>
ます。
入力 XML:
<?xml version="1.0"?>
<chapter xmlns="http://www.w3.org/1998/Math/MathML">
<style>This is style</style>
<math display="block">
<munder>
<mi mathvariant="normal">BASE</mi>
<mi mathvariant="normal">under</mi>
</munder>
<mo>=</mo>
<munder>
<mrow>
<munder>
<mi mathvariant="normal">BASE</mi>
<mi mathvariant="normal">under</mi>
</munder>
</mrow>
<mphantom>
<mi mathvariant="normal">under</mi>
</mphantom>
</munder>
</math>
<b>This is bold</b>
</chapter>
XSLT が試した:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:mml="http://www.w3.org/1998/Math/MathML">
<xsl:output method="xml" encoding="UTF-8" indent="no"/>
<xsl:strip-space elements="*"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
必要な出力:
<?xml version='1.0' encoding='UTF-8'?>
<chapter xmlns="http://www.w3.org/1998/Math/MathML"><style>This is style</style> <math display="block"><munder><mi mathvariant="normal">BASE</mi><mi mathvariant="normal">under</mi></munder><mo>=</mo><munder><mrow><munder><mi mathvariant="normal">BASE</mi><mi mathvariant="normal">under</mi></munder></mrow><mphantom><mi mathvariant="normal">under</mi></mphantom></munder></math> <b>This is bold</b></chapter>