XSLT function element-available failed in Xalan for the extension which not actually used

2 views
Skip to first unread message

Stephen Suen

unread,
Mar 30, 2006, 4:41:49 AM3/30/06
to [Programmer Cafe]
In xalan-j_2_7_0, XSLT function element-available failed for the
extension which not actually used. Sometimes, it causes
NullPointerException, and sometimes just returns false.
Here's the stylesheet caused the problem:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:redirect="http://xml.apache.org/xalan/redirect"
xmlns:xalanredirect="org.apache.xalan.xslt.extensions.Redirect"
extension-element-prefixes="xalanredirect redirect"
version="1.0">

<xsl:template match="/">
<xsl:message>
<xsl:text>XSL Vendor: </xsl:text>
<xsl:value-of select="system-property('xsl:vendor')"/>
</xsl:message>

<xsl:choose>
<xsl:when test="element-available('xalanredirect:write')">
<xsl:message>
<xsl:text>xalanredirect:write available</xsl:text>
<xalanredirect:write file="dummy1.xml"/> <!-- **** -->
</xsl:message>
</xsl:when>
<xsl:otherwise>
<xsl:message>
<xsl:text>xalanredirect:write NOT available</xsl:text>
</xsl:message>
</xsl:otherwise>
</xsl:choose>

<xsl:choose>
<xsl:when test="element-available('redirect:write')">
<xsl:message>
<xsl:text>redirect:write available</xsl:text>
</xsl:message>
<redirect:write file="dummy2.xml"/> <!-- **** -->
</xsl:when>
<xsl:otherwise>
<xsl:message>
<xsl:text>redirect:write NOT available</xsl:text>
</xsl:message>
</xsl:otherwise>
</xsl:choose>

</xsl:template>

</xsl:stylesheet>

Removing any one of the two lines indicated by <!-- **** -->, will cause
the corresponding element-available test to fail. Here's the command line:

E:\xslt>SET CLASSPATH=E:\apache\xalan-j_2_7_0\serializer.jar;E:\apache\xalan-j_2
_7_0\xalan.jar;E:\apache\xalan-j_2_7_0\xercesImpl.jar;E:\apache\xalan-j_2_7_0\xm
l-apis.jar

E:\xslt>java -Duser.language=en org.apache.xalan.xslt.Process -in index.xml -xsl
style.xsl
file:///E:/xslt/style.xsl; Line #10; Column #16; XSL Vendor: Apache Software Fou
ndation
file:///E:/xslt/style.xsl; Line #17; Column #20; xalanredirect:write available
file:///E:/xslt/style.xsl; Line #36; Column #20; redirect:write NOT available
<?xml version="1.0" encoding="UTF-8"?>

If both lines removed, transforming will fail:

E:\xslt>SET CLASSPATH=E:\apache\xalan-j_2_7_0\serializer.jar;E:\apache\xalan-j_2
_7_0\xalan.jar;E:\apache\xalan-j_2_7_0\xercesImpl.jar;E:\apache\xalan-j_2_7_0\xm
l-apis.jar

E:\xslt>java -Duser.language=en org.apache.xalan.xslt.Process -in index.xml -xsl
style.xsl
file:///E:/xslt/style.xsl; Line #10; Column #16; XSL Vendor: Apache Software Fou
ndation

file:///E:/xslt/style.xsl; Line #16; Column #63; XSLT Error (javax.xml.transform
.TransformerException): Unknown error in XPath.
Exception in thread "main" java.lang.RuntimeException: Unknown error in XPath.
at org.apache.xalan.xslt.Process.doExit(Process.java:1153)
at org.apache.xalan.xslt.Process.main(Process.java:1126)


I'm trying to confirm this problem as a bug of Xalan.

--
Stephen Suen
stephe...@gmail.com
http://spaces.msn.com/members/stephensuen
http://groups.google.com/group/programmercafe

Reply all
Reply to author
Forward
0 new messages