Announcement Announcement Module
Collapse
No announcement yet.
Using XSLT Components in Spring MVC Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using XSLT Components in Spring MVC

    I while ago I wrote a Java application that processes XML with XSLT using Xalan. Now I'm trying to move towards Spring.

    I've been having trouble accessing components. As far as I can tell my XML, XSLT and Java objects are correct, but Spring cannot seem to find and reference the components I want to access. I also tried adding a JavaScript component (with bsf.jar and js.jar) in a separate file and that also fails to compile the template.

    ...
    <axslt:component prefix="oni" functions="say">
    <axslt:script lang="javaclass" src="xslt.components.TestComponent" />
    </axslt:component>
    ...

    ...
    <axslt:component prefix="js" functions="say">
    <xalan:script lang="javascript">
    function say() { return "Hello from JavaScript"; }
    </xalan:script>
    </axslt:component>
    ...

    I consistently get this error:

    javax.xml.transform.TransformerConfigurationExcept ion: Could not compile stylesheet
    com.sun.org.apache.xalan.internal.xsltc.trax.Trans formerFactoryImpl.newTemplates(Unknown Source)
    org.springframework.web.servlet.view.xslt.XsltView .loadTemplates(XsltView.java:417)
    ...

    I've looked online and haven't found a lot to go on. Spring+XSLT doesn't seem to be a very prominent topic. Any suggestions on something in Spring I need to configure, or something I would need to extend?

  • #2
    Look deeper at the exception. There might be a nested, inner, exception with a more detailed message or type.

    Try to perform the transformation outside Spring first. Once that works, you may want to overwrite XsltView's renderMergedOutputModel(..) or createTransformer(..) methods.

    See http://xml.apache.org/xalan-j/usagepatterns.html#basic for a sample transformation.

    One catch might be which javax.xml.transform.TransformerImpl to use:
    Spring - in TemplatesImpl.newTransformer() - instantiates a com.sun.org.apache.xalan.internal.xsltc.trax.Trans formerImpl (which is the default for Sun Java).
    You might need a org.apache.xalan.transformer.TransformerImpl instead.

    Comment

    Working...
    X