我想使用 xslt 从 Mathml 输入中输出数学表达式。我的变换一定有什么错误。我不知道如何纠正它。你可以帮帮我吗?我应该使用参数还是变量来控制它?xml:
<?xml version="1.0" encoding="UTF-8"?>
<math>
<apply>
<eq/>
<apply>
<plus/>
<apply>
<power/>
<ci>x</ci>
<cn>2</cn>
</apply>
<apply>
<times/>
<cn>2</cn>
<ci>x</ci>
</apply>
<cn>2</cn>
</apply>
<cn>0</cn>
</apply>
</math>
这是我的 xsl:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="UTF-8"/>
<xsl:template match="/">
<xsl:apply-templates/>
<xsl:text> </xsl:text>
</xsl:template>
<xsl:template match="math">
<xsl:apply-templates select="apply"/>
</xsl:template>
<xsl:template match="apply">
<xsl:sequence select="name(element()[1]),'('"/>
<xsl:apply-templates select="apply">
</xsl:apply-templates>
<xsl:sequence select="element()[2],','"/>
<xsl:sequence select="element()[3],')',','"/>
</xsl:template>
</xsl:stylesheet>
结果应该是:
eq(plus(power(x,2),times(2,x),2),0)