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

Mehmet Birgi mehmet.birgi at wyona.com
Tue Apr 20 09:42:50 CEST 2010


On Tue, Apr 20, 2010 at 9:34 AM, Michael Wechner
<michael.wechner at wyona.com>wrote:

> Guillaume D=E9flache wrote:
>
>> Michael Wechner schrieb:
>>
>>> Guillaume D=E9flache 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/SAXTrans=
formerFactory.html#newTransformerHandler(javax.xml.transform.Source)<http:/=
/java.sun.com/javase/6/docs/api/javax/xml/transform/sax/SAXTransformerFacto=
ry.html#newTransformerHandler%28javax.xml.transform.Source%29>>).
>>>>
>>>>
>>>
>>> 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/s=
rc/java/org/wyona/yanel/impl/resources/navigation/NavigationResource.java
>>
>
> so you received a NullPointer at the following line:
>
>
> xsltHandlers[i] =3D 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 =3D repo.getNode(xsltPath[i]);
>
>  InputStream is =3D node.getInputStream()
>
>   StreamSource ss =3D new StreamSource(is)
>
>> xsltHandlers[i] =3D tf.newTransformerHandler(ss);
>>
>
> and then received the NullPointer on the line of newTransformerHandler
> which means something is wrong with the XSLT


That's exactly what we did :-)

>
>
>>
>>  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 thi=
s 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/s=
rc/java/org/wyona/yanel/impl/resources/navigation/NavigationResource.javath=
ere is:
>> xsltHandlers[i] =3D 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=3D"yanel:foo"/>
>>
>
> so you are saying that the namespace declaration was missing, e.g.
>
> <xsl:stylesheet version=3D"1.0"
>  xmlns:xsl=3D"http://www.w3.org/1999/XSL/Transform"
>  xmlns:yanel=3D"http://www.wyona.org/yanel/1.0"
>
> right?
>

Yes, that was it.  And what helped us find it in the end was a tool called
xsltproc (http://xmlsoft.org/XSLT/xsltproc2.html), which is basically a
command line transformer. The simplest usage in this case is:

> xsltproc header.xsl header.xsl

It pointed out the error immediately (that the namespace was undeclared).

Cheers,

Memo



>
> Thanks
>
> Michi
>
>
>>  instead of complaining loudly, which can be extremly confusing.
>>>>
>>>
>>> which method didn't complain?
>>>
>>
>> SAXTransformerFactory#newTransformerHandler as written above.
>>
>> Cheers,
>>   Guillaume
>>
>
> --
> Yanel-development mailing list Yanel-development at wyona.com
> http://lists.wyona.org/cgi-bin/mailman/listinfo/yanel-development
>



-- =

Mehmet Birgi
www.wyona.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wyona.org/pipermail/yanel-development/attachments/2010042=
0/d201f2f5/attachment.htm


More information about the Yanel-development mailing list