Sushant Sinha schrieb am 04.02.2011 um 15:08 (+0530):
> I am using xalan 2.7.1 for transforming an xml document using an xsl
> stylesheet. I have attached the input xml as example.xml and the rule
> as rule.xsl.
Hmm, the XML file is ~ 128 KB and probably irrelevant. I'm pasting the
XSLT here so people can read it without the unpacking hassle:
\,,,/
(o o)
------oOOo-(_)-oOOo------
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:xalan="http://xml.apache.org/xalan"
exclude-result-prefixes="xalan">
<xsl:template match="/">
<xsl:variable name="business_name"
select="normalize-space(/html/span/xpath)"/
<xsl:if test="count(xalan:nodeset($business_name)) < 2">
</xsl:if>
</xsl:template>
</xsl:stylesheet>
-------------------------
So you're selecting a string (return value of normalize-space()) and
then you're calling the nodeset() function on it - that doesn't make
any sense, because you can't hope to have a nodeset here.
> rule.xsl uses xalan extension function xalan:nodeset() and the
> transformation runs fine with the interpretive xalan. However, it
> fails when the property avax.xml.transform.TransformerFactory is set
> to org.apache.xalan.xsltc.trax.TransformerFactoryImpl
>
> It actually produces a java exception with the following stack:
>
> ERROR: 'Invalid conversion from 'node-set' to 'java.lang.String'.'
> Exception in thread "main" javax.xml.transform.TransformerException:
> java.lang.RuntimeException: Invalid conversion from 'node-set' to
> 'java.lang.String'.
> Is this a bug in the compiled xsltc processor? Or is there a usage
> issue?
It is a usage issue. Can't say if it also a bug.
Here's a similar case (without the Xalan dependency):
\,,,/
(o o)
------oOOo-(_)-oOOo------
<xsl:stylesheet version="1.0"
xmlns:exsl="http://exslt.org/common"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:variable name="a" select="string( . )"/>
<r>
<a><xsl:value-of select="$a"/></a>
<b><xsl:value-of select="exsl:node-set( $a )"/></b>
</r>
</xsl:template>
</xsl:stylesheet>
-------------------------
Works fine for LibXSLT, Xalan and Saxon 9.1. (Which doesn't go to say
that it makes sense.) Saxon 6.5, on the other hand, reports an error:
exslt:node-set(): argument must be a node-set or tree
Also note that EXSLT is preferred over xalan:nodeset().
http://xml.apache.org/xalan-j/extensions_xsltc.html#nodeset_ext
--
Michael Ludwig