星期一, 七月 26, 2004

Xalan XSLT extension Javascript/java出现错误:

使用的javascript:engine:
http://www.mozilla.org/rhino/download.html 1.5R5

出现错误:Line number can not be negative:-1

这是Bug,必须使用:1.5 R3版本.可以正常使用.

extension使用Java出现错误:
不能正确映射Java对象的方法:
For extension function, could not find method static java.lang.System.currentTimeMills([ExpressionContext,] ).
原因:拼写错误.
------------------
例子:
<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xalan="http://xml.apache.org/xalan"
exclude-result-prefixes="xalan"
xmlns:java="http://xml.apache.org/xalan/java"
xmlns:my-ext="ext1"
extension-element-prefixes="my-ext"
>
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:param name="employment"/>
<xsl:param name="basicinfo"/>
<xsl:param name="paymentinfo"/>
<xsl:param name="attendance"/>


<xalan:component prefix="my-ext" functions="getdate">
<xalan:script lang="javascript">
var aaa=1;
function getdate()
{
return "ddd";
}
</xalan:script>
</xalan:component>


<xsl:template match="/">
<xsl:choose>
<xsl:when test="not($employment)">
<xsl:text>Nothing</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>Yeah</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:text> </xsl:text>
<xsl:value-of select="my-ext:getdate()"/>
<xsl:text> </xsl:text>
<xsl:value-of select="$employment/employe/name"/>
<xsl:text> </xsl:text>
<xsl:value-of select="java:java.lang.Math.random()" />
<xsl:text> </xsl:text>
<xsl:value-of select="java:java.lang.System.currentTimeMillis()" />
</xsl:template>
</xsl:stylesheet>