符号导数计算器不起作用 - XSLT

时间:2015-11-10 02:12:11

标签: xml xslt

我正在做一个简单的XSLT模板练习,它应该计算带有链规则的简单表达式的导数,如(x ^ 2 + 5)^ 6,并且应该返回6(x ^ 2 + 5)* 2x,我正在使用模板,模式允许复制内部表达式,“递归地”调用其他模板来完成剩下的工作。

据我所知,你从树的根开始,在匹配模式中进一步向下进入特定情况,例如有一个X ^ 2但不是常数。

我不明白什么是错的,因为它意味着在大约30行中完成,现在是27,并求求你的帮助。

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <html>
        <body>
            <xsl:apply-templates select="f"/>
        </body>
    </html>
    <xsl:template match="f">
        <xsl:apply-templates select="power/const" mode="derivar"/>
    </xsl:template>

    <xsl:template match="power/const" mode="derivar">
        <xsl:value-of select=" power * const"/>
        <xsl:apply-templates select="plus/power/const" mode="copy"/>
        <xsl:value-of select="power -1"/>
        <p>*</p>
        <xsl:apply-templates select = "plus/power/const" mode="derivar"/>
    </xsl:template>

    <xsl:template match="plus/power/const"  mode="copy">
        <xsl:value-of select="var"/>
        <xsl:value-of select="power"/>
        <p>+</p>
        <xsl:value-of select="const"/>
    </xsl:template>

    <xsl:template match="plus/power/const" mode ="derivar">
        <xsl:value-of select="const * power"/>
        <xsl:value-of select="var"/>
        <xsl:value-of select="power -1"/>
    </xsl:template>
</xsl:stylesheet>

0 个答案:

没有答案