[Yanel-dev] [FYI] SAXTransformerFactory#newTransformerHandler returning null

Michael Wechner michael.wechner at wyona.com
Tue Apr 20 09:34:15 CEST 2010


Guillaume Déflache wrote:
> Michael Wechner schrieb:
>> Guillaume Déflache wrote:
>>> Hi!
>
> Hi!
>
>
>>> When using XSLT via the JAXP API, you may use the 
>>> SAXTransformerFactory#newTransformerHandler(Source) method 
>>> (<http://java.sun.com/javase/6/docs/api/javax/xml/transform/sax/SAXTransformerFactory.html#newTransformerHandler(javax.xml.transform.Source)>). 
>>>
>>
>> instead of what?
>
> Describing an alternative way was not the point here, we just used 
> what's in 
> http://svn.wyona.com/repos/public/yanel/trunk/src/resources/navigation/src/java/org/wyona/yanel/impl/resources/navigation/NavigationResource.java

so you received a NullPointer at the following line:

xsltHandlers[i] = tf.newTransformerHandler(new 
StreamSource(repo.getNode(xsltPath[i]).getInputStream()));

but it was not clear which call exactly created the NullPointer, right?

In order to find out you have split this line into several lines, e.g.

    Node node = repo.getNode(xsltPath[i]);

   InputStream is = node.getInputStream()

    StreamSource ss = new StreamSource(is)
> xsltHandlers[i] = tf.newTransformerHandler(ss);

and then received the NullPointer on the line of newTransformerHandler
 which means something is wrong with the XSLT
>
>
>>> Please be aware than with Xalan (2.7.1 at least) this method may 
>>> only return null if your XSLT is incorrect for some reason (in our 
>>> case this was a namespace used in XPath that never got declared),
>>
>> can you give a more concrete example?
>
> In 
> http://svn.wyona.com/repos/public/yanel/trunk/src/resources/navigation/src/java/org/wyona/yanel/impl/resources/navigation/NavigationResource.java 
> there is:
> xsltHandlers[i] = tf.newTransformerHandler(new 
> StreamSource(repo.getNode(xsltPath[i]).getInputStream()));
> The variable is set to null when e.g. the Yanel NS namespace has not 
> been associated with the 'yanel' prefix in e.g. <xsl:value-of 
> select="yanel:foo"/>

so you are saying that the namespace declaration was missing, e.g.

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:yanel="http://www.wyona.org/yanel/1.0"

right?


Thanks

Michi
>
>>> instead of complaining loudly, which can be extremly confusing.
>>
>> which method didn't complain?
>
> SAXTransformerFactory#newTransformerHandler as written above.
>
> Cheers,
>    Guillaume



More information about the Yanel-development mailing list