You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Daryl Beattie <Da...@screamingmedia.com> on 2001/03/09 21:09:13 UTC

Incorrect handling of x-path substring-before and substring-after ? XalanJ2 error messages?

Dear Xalan Developers,

	Please forgive me if this problem has already been addressed (I
checked the archives, but found no messages that adressed this). I'm using
Xalan 2.0.0 and whichever Xerces shipped with the dist.
	It seems that when I pass an empty string into substring-before and
substring-after, like this:

<?xml version="1.0"?>
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<xsl:variable name="str"></xsl:variable>
<xsl:variable name="bob"><xsl:value-of
select='substring-after($str,"&apos;")'/></xsl:variable>
<xsl:if test="$bob">
	<xsl:text>hello!</xsl:text>
</xsl:if>
</xsl:template>

</xsl:transform>

	According to my XSLT book (Wrox Press book by Michael Kay) in two
places it mentions that "if the containing string does not contain the test
substring, the function returns an empty string". It also mentions that an
empty string should evaluate to falst, not true.
	The above style-sheet can be run on any XML file. With XalanJ1
[XalanJ1.2.2 dist.] it produces an empty document (as I believe it should),
but in XalanJ2 [XalanJ2.0.0 dist.] it produces a document with the text
"hello!" in it.
	Recursive algorithms that rely on code such as this could loop
indefinitely, until the Java VM runs out of memory and the program crashes.

	Also, unrelated to the above problem, I have noticed that the
error-reporting seems to be better for XalanJ1 than for XalanJ2. I get
descriptive messages about problems with my style-sheets with XalanJ1,
whereas XalanJ2 just runs them either succeeding or failing without a
message. Am I doing something wrong? For example, these are two runs of a
style-sheet. This is XalanJ2:


C:\projects\converter\bin>java -cp
c:\projects\converter\thirdparty\lib\xalan.jar;c:\projects\converter\thirdpa
rty\lib\x
erces.jar org.apache.xalan.xslt.Process -IN
file:///c:\projects\converter\dboutput.xml -XSL file:///c:\projects\convert
er\test.xsl -OUT c:\projects\converter\test.txt

	There is no error, and the output is blank.
	This is XalanJ1:

C:\projects\converter\bin>java -cp
c:\projects\converter\thirdparty\lib\xalan1.jar;c:\projects\converter\thirdp
arty\lib\
xerces123.jar org.apache.xalan.xslt.Process -IN
file:///c:\projects\converter\dboutput.xml -XSL file:///c:\projects\con
verter\test.xsl -OUT c:\projects\converter\test.txt
========= Parsing file:/c:/projects/converter/test.xsl ==========
XSL Error: Could not parse file:/c:/projects/converter/test.xsl document!
XSL Error: processStylesheet not successful!
XSLT: (StylesheetHandler) xsl:if not allowed inside a stylesheet!
Xalan: was not successful.
XSLProcessor: done

	This makes bugs very hard to track in XalanJ2. Is there anything I
can do to get better error reporting?

Sincerely,

	Daryl.