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 using jdk1.5.0_04 with xalan-j_2_7_0.

Is this a bug of Xalan?  I searched the bug database, but nothing
found about this.
Should I report it?

--
Stephen Suen
[EMAIL PROTECTED]

Reply via email to