如何在 xslt 中计算三角函数 sin & cos



我正在使用Xalan Java,我必须在XSLT中计算sin ((和cos ((。 这是我的例子

 <?xml version="1.0"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:math ="http://www.w3.org/2005/xpath-functions/math"
        extension-element-prefixes="math"> 
        version="1.0">
        <xsl:output method="xml" indent="yes"/>
        <xsl:template match = "root/module[start-with(@name, phase)]">
            <xsl:variable name ="k" select ="0.0"=/>
            <xsl:variable name = "angle" select ="math:cos(k)"/>
            <theta x = "$angle">
            </theta>
        </xsl:template>
    </xsl:stylesheet>

注意:这只是我尝试但失败的示例方法,您能否提供一个如何在 XSLT 中计算三角函数的示例。

谢谢

使用 Saxon 9.6 或更高版本,然后

例如
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
    xmlns:math="http://www.w3.org/2005/xpath-functions/math" exclude-result-prefixes="math">
    <xsl:template match="/">
        <result>
            <xsl:value-of select="math:sin(math:pi() div 2)"/>
        </result>
    </xsl:template>
</xsl:transform>

应该工作正常。

最新更新