我想使用xslt从Mathml输入输出数学表达式。我的转变肯定有一些错误。我不知道如何纠正它。你可以帮帮我吗?我应该使用参数还是变量来控制它? XML:使用xsl输出数学表达式
<?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)
@empo,我想知道,如果你的编辑应该有被包括在答案中而不是问题中;感觉就像你知道你在做什么:)但我不知道你是否在做他们。 :) – sarnold 2011-05-21 21:25:23
@sarnold:他们应该是安全的编辑,这使问题变得清晰。我已将缺少的部分代码添加到声明所用版本的xslt中。我设置了2.0版本,因为OP使用了XSLT 2.0中的元素和功能。 – 2011-05-21 21:36:40
@empo,优秀!谢谢。 :) – sarnold 2011-05-21 21:39:53