[jdom-interest] XSL problem - null pointer exception

Ian Lea ian.lea at blackwell.co.uk
Thu Jan 31 03:18:50 PST 2002


I can't tell what is wrong from this, but if you send a complete
standalone program that will run out of the box, and the stylesheet,
both as small as possible to demonstrate the problem, I'll have a
play with it.


--
Ian.
ian.lea at blackwell.co.uk

Simon McLeish wrote:
> 
> Can anyone help me? I'm trying to use an XSL transform in a method in an
> application I'm developing. I'm using code from the JDOM website, which
> should work (!), and my stylesheet should be valid (I can do the
> transform manually using SAXON from the command line).
> 
> TIA,
> Simon
> 
> Details:
> 
> I get the following error:
> 
> javax.xml.transform.TransformerConfigurationException:
> javax.xml.transform.TransformerConfigurationException:
> javax.xml.transform.TransformerException: java.lang.NullPointerException
>          at
> org.apache.xalan.processor.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:764)
>          at
> ArchiveSearchResults.quickTransform(ArchiveSearchResults.java:546)
> (plus a lot more in a similar vein)
> 
> Online searches say that this is usually caused by a problem with the
> stylesheet, but I don't think this is what's happening here.
> 
> Here's the relevant code. I've changed the parameter to the StreamSource
> initializer to a java.io.File instead of the filename as a String, as
> that's what the docs say it should be, and added a few lines to stop
> getting a compilation error because returnDoc is sometimes null.
> 
> public static Document quickTransform(Document in, File stylesheet) {
>      // based on code found in the JDOMSource documentation
> 
>      // following is so that returnDoc is not null even if try fails
>      ArrayList nullList = new ArrayList();
>      Element startElement = new Element("HTML");
>      nullList.add(startElement);
>      Document returnDoc = new Document(nullList);
> 
>      // set up variables so don't get null pointer errors
>      TransformerFactory transformerFactory =
> TransformerFactory.newInstance();
>      StreamSource stylesheetSource = new StreamSource(stylesheet);
> 
>      try {
>        Transformer transformer =
> transformerFactory.newTransformer(stylesheetSource);
>        JDOMResult out = new JDOMResult();
>        transformer.transform(new JDOMSource(in), out);
>        returnDoc = out.getDocument();
>      }
>      catch (javax.xml.transform.TransformerException e) {
>        e.printStackTrace();
>      }
>      return returnDoc;
>    }



More information about the jdom-interest mailing list