Calling Java API from XSL throws exception “The URI http://xml.apache.org/xslt/java does not identify an external Java class”

南笙酒味 提交于 2019-12-12 03:49:18

问题


I'm using SAXON processor for xsl file as follows:

   <?xml version="1.0" encoding="utf-8"?>
   <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                    version="1.0" xmlns:java="http://xml.apache.org/xslt/java"
                    exclude-result-prefixes="java">
    <xsl:output method="xml"/>
    <xsl:template name="printjavaDate">
    <xsl:variable name="date" select="java:java.util.Date.new()"/>
    <xsl:value-of select=""/>
    </xsl:template>

But this code isn't working for me.

It throws error:

javax.xml.transform.TransformerException: The URI http://xml.apache.org/xslt/java does not identify an external Java class
                at com.icl.saxon.style.StyleElement.styleError(StyleElement.java:803)

I'm not sure why is this happening. I've requirement of using XSLT 1.0 only.

Can I know what is causing this error? Hope experts here will help me out.


回答1:


I guess xmlns:java="http://xml.apache.org/xslt/java" is Xalan specific, if you want to use extension functions in Saxon 6 then see http://saxon.sourceforge.net/saxon6.5.5/extensibility.html.

Here is an example that works for me with Saxon 6.5:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
    xmlns:date="java:java.util.Date">

    <xsl:output method="xml"/>

    <xsl:template name="printjavaDate" match="/">
        <xsl:variable name="date" select="date:new()"/>
        <xsl:value-of select="$date"/>
    </xsl:template>

</xsl:stylesheet>


来源:https://stackoverflow.com/questions/39528609/calling-java-api-from-xsl-throws-exception-the-uri-http-xml-apache-org-xslt-j

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!