我想从<mo>
(</mo>
直到<mo>
)转变</mo>
为<mfenced>
...... </mfenced>
示例输入如下:
示例 XML:
<?xml version="1.0" encoding="UTF-8"?>
<chapter xmlns="http://www.w3.org/1998/Math/MathML">
<p>
<math>
<mi>sin</mi>
<mo>(</mo>
<mi>x</mi>
<mi>y</mi>
<mo>)</mo>
<mo>=</mo>
<mi>sin</mi>
<mi>x</mi>
<mi>sin</mi>
<mi>y</mi>
</math>
</p>
</chapter>
XSLT 2.0 试过:
<?xml version='1.0'?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:m="http://www.w3.org/1998/Math/MathML"
xmlns="http://www.w3.org/1998/Math/MathML"
exclude-result-prefixes="m">
<xsl:output method="xml"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="m:mo">
<xsl:if test="(.)='('">
<mfenced><xsl:apply-templates select="following-sibling::*[(.)=')']" mode="copy"/>
</mfenced>
</xsl:if>
<xsl:if test="(.)=')'"></xsl:if>
</xsl:template>
<xsl:template match="m:mo" mode="copy"/>
</xsl:stylesheet>
需要输出:
<?xml version="1.0" encoding="UTF-8"?>
<chapter xmlns="http://www.w3.org/1998/Math/MathML">
<p>
<math>
<mi>sin</mi>
<mfenced>
<mi>x</mi>
<mi>y</mi>
</mfenced>
<mo>=</mo>
<mi>sin</mi>
<mi>x</mi>
<mi>sin</mi>
<mi>y</mi>
</math>
</p>
</chapter>