Google App Engine + XSLT

Google App Engine (java) doesn’t do XSLT transformations out of the box. Using a Transformer like

TransformerFactory.newInstance().newTransformer(new StreamSource(...)).transform(...);

yields a

Nested in javax.servlet.ServletException: java.lang.NoClassDefFoundError: com.sun.org.apache.xalan.internal.xsltc.runtime.BasisLibrary is a restricted class. Please see the Google App Engine developer's guide for more details.:
java.lang.NoClassDefFoundError: com.sun.org.apache.xalan.internal.xsltc.runtime.BasisLibrary is a restricted class. Please see the Google App Engine developer's guide for more details.

These google groups posts http://code.google.com/p/googleappengine/issues/detail?id=1452 and http://groups.google.com/group/google-appengine-java/browse_thread/thread/9c9fb88e1b175395 lead into the right direction but didn’t completely solve my problem. I added xalan.jar and serializer.jar from xalan-2.7.1 to war/WEB_INF/lib as suggested, but didn’t change the TransformerFactory setup.

This got me the WARNING log entries Failed calling setMethod method and Failed calling setIndent method.

This cyrillc blog-post lead me to removing all <xsl:output/> statements from the transformation and voilá – the trafo ran fine!

The whole procedure in short:

  • add xalan.jar and serializer.jar to war/WEB_INF/lib,
  • remove <xsl:output/> from the stylesheet.

Flattr this!

Post a Comment

Your email is never published nor shared. Required fields are marked *