xsl里添了了一个script,代码如下:<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:DateFuncs="dfuncs">
<xsl:output omit-xml-declaration="yes" encoding="UTF-8" method="html"/>
<!-- External scripts -->
<msxsl:script language="VBScript" implements-prefix="DateFuncs">
<![CDATA[
' Input : from_date (yyyymmdd), to_date (yyyymmdd)
' Returns: number of days between from_date and to_date (to_date not included)
Function DaysBetween(from_date, to_date)
Dim d1, d2
if len(from_dt) <> 8 or len(to_dt) <> 8 _
then
DaysBetween = -1
end if
' Translate to format yyyy-mm-dd
d1 = left(from_date,4) & "-" & mid(from_date,5,2) & "-" & right(from_date,2)
d2 = left(to_date,4) & "-" & mid(to_date,5,2) & "-" & right(to_date,2)
if not isdate(d1) or not isdate(d2) _
then
DaysBetween = -1
else
DaysBetween = DateDiff("d", CDate(d1), CDate(d2))
end if
End Function
]]>
</msxsl:script>
<xsl:template name="daysBetween">
<xsl:param name="v_from_date"/>
<xsl:param name="v_to_date"/>
<xsl:value-of select="DateFuncs:DaysBetween(substring($v_from_date,1),substring($v_to_date,1))"/>
</xsl:template><!-- 调用 -->
<xsl:call-template name="daysBetween">
<xsl:with-param name="v_from_date" select="./xmlsum/usg[@type='XPLN']/d7/d7[@type='GSM']/fromdt"/>
<xsl:with-param name="v_to_date" select="./xmlsum/usg[@type='XPLN']/d7/d7[@type='GSM']/todt"/>
</xsl:call-template>在java中解析的代码
InputStream xmlStream = new ByteArrayInputStream(invoiceContent.getBytes("UTF-8"));
InputStream xsltStream = new ByteArrayInputStream(
OVRefreshCache.getURLContent(basePath + xslFile).getBytes("UTF-8"));
Source xsltSource = new StreamSource(xsltStream); TransformerFactory factory = TransformerFactory.newInstance();
Transformer trans = factory.newTransformer(xsltSource);
result = new StreamResult(new ByteArrayOutputStream());
trans.transform(new StreamSource(xmlStream), result);执行最后一句的时候报错:
(错误位置未知)java.lang.NoSuchMethodException: For extension function, could not find method java.lang.String.DaysBetween([ExpressionContext,] #STRING).
请帮忙看一下,谢谢!
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:DateFuncs="dfuncs">
<xsl:output omit-xml-declaration="yes" encoding="UTF-8" method="html"/>
<!-- External scripts -->
<msxsl:script language="VBScript" implements-prefix="DateFuncs">
<![CDATA[
' Input : from_date (yyyymmdd), to_date (yyyymmdd)
' Returns: number of days between from_date and to_date (to_date not included)
Function DaysBetween(from_date, to_date)
Dim d1, d2
if len(from_dt) <> 8 or len(to_dt) <> 8 _
then
DaysBetween = -1
end if
' Translate to format yyyy-mm-dd
d1 = left(from_date,4) & "-" & mid(from_date,5,2) & "-" & right(from_date,2)
d2 = left(to_date,4) & "-" & mid(to_date,5,2) & "-" & right(to_date,2)
if not isdate(d1) or not isdate(d2) _
then
DaysBetween = -1
else
DaysBetween = DateDiff("d", CDate(d1), CDate(d2))
end if
End Function
]]>
</msxsl:script>
<xsl:template name="daysBetween">
<xsl:param name="v_from_date"/>
<xsl:param name="v_to_date"/>
<xsl:value-of select="DateFuncs:DaysBetween(substring($v_from_date,1),substring($v_to_date,1))"/>
</xsl:template><!-- 调用 -->
<xsl:call-template name="daysBetween">
<xsl:with-param name="v_from_date" select="./xmlsum/usg[@type='XPLN']/d7/d7[@type='GSM']/fromdt"/>
<xsl:with-param name="v_to_date" select="./xmlsum/usg[@type='XPLN']/d7/d7[@type='GSM']/todt"/>
</xsl:call-template>在java中解析的代码
InputStream xmlStream = new ByteArrayInputStream(invoiceContent.getBytes("UTF-8"));
InputStream xsltStream = new ByteArrayInputStream(
OVRefreshCache.getURLContent(basePath + xslFile).getBytes("UTF-8"));
Source xsltSource = new StreamSource(xsltStream); TransformerFactory factory = TransformerFactory.newInstance();
Transformer trans = factory.newTransformer(xsltSource);
result = new StreamResult(new ByteArrayOutputStream());
trans.transform(new StreamSource(xmlStream), result);执行最后一句的时候报错:
(错误位置未知)java.lang.NoSuchMethodException: For extension function, could not find method java.lang.String.DaysBetween([ExpressionContext,] #STRING).
请帮忙看一下,谢谢!
XslCompiledTransform xslt = new XslCompiledTransform();
string xslPath = Server.MapPath("productlist.xsl");
XsltSettings axslset = new XsltSettings();
axslset.EnableScript = true;
xslt.Load(xslPath, axslset,new XmlUrlResolver());Java的没有找到解决的办法