0 Replies Latest reply on Jun 25, 2014 9:09 AM by Allan Cheong

    camel-xslt: xsl output only has outermost xml tag with no content within

    Allan Cheong Newbie



      I am using JDK7 and Fuse 6.1.0.redhat-379.

      My route is a simple get from URI, then XSLT and save to File. For instance:

      <route id="route">

           <from uri="direct:start" />

           <to uri="http4://www.example.com" />

           <to uri="xslt:com/playground/poc/transform.xsl" />

           <to uri="file:work?fileName=output.xml" />



      I faced the exact problem as mentioned in Apache Camel website, XSLT component section (link). An excerpt:

      Here are some observations from Sameer, a Camel user, which he kindly shared with us:

      In case anybody faces issues with the XSLT endpoint please review these points.

      I was trying to use an xslt endpoint for a simple transformation from one xml to another using a simple xsl. The output xml kept appearing (after the xslt processor in the route) with outermost xml tag with no content within.

      No explanations show up in the DEBUG logs. On the TRACE logs however I did find some error/warning indicating that the XMLConverter bean could no be initialized.

      After a few hours of cranking my mind, I had to do the following to get it to work (thanks to some posts on the users forum that gave some clue):

      1. Use the transformerFactory option in the route ("xslt:my-transformer.xsl?transformerFactory=tFactory") with the tFactory bean having bean defined in the spring context for class="org.apache.xalan.xsltc.trax.TransformerFactoryImpl".
      2. Added the Xalan jar into my maven pom.


      I followed the steps but when I started the bundle, this exception appeared:

      ERROR: Bundle eip [301] EventDispatcher: Error during dispatch. (java.lang.NoClassDefFoundError: org/apache/xalan/xsltc/compiler/Parser)

      java.lang.NoClassDefFoundError: org/apache/xalan/xsltc/compiler/Parser

              at org.apache.xalan.xsltc.compiler.XSLTC.<init>(XSLTC.java:141)

              at org.apache.xalan.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:742)

              at org.apache.camel.builder.xml.XsltBuilder.setTransformerSource(XsltBuilder.java:329)

              at org.apache.camel.component.xslt.XsltEndpoint.loadResource(XsltEndpoint.java:112)

              at org.apache.camel.component.xslt.XsltEndpoint.doStart(XsltEndpoint.java:121)


      I suspect it is something to do with the OSGI dependencies that I might have missed out installing. Has anyone also encountered this and could advise?


      EDIT: I've installed the servicemix dependencies that are OSGI compliant - bcel and xalan. Still, the same exception occurs when I start my bundle.


      EDIT: I've found another way to get it working by using saxon instead of xalan. Simply, inject this bean


      <bean id="transformerFactory" class="net.sf.saxon.TransformerFactoryImpl" />


      into the XSLT routing endpoint.


      <to uri="xslt:com/playground/poc/transform.xsl?transformerFactory=transformerFactory" />


      Hope this helps!