Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: XSLT Transform

  1. #1
    Join Date
    May 2006
    Posts
    11

    Default XSLT Transform

    Hello,

    I am trying to get the example from the Spring reference manual in the XSLT views section working. I have everything setup exactly how it is in the example, but I get an exception when I load up the page. The weird thing about the exception is that it comes from an oracle library. Am I missing a library, or are my imports wrong? Here is the exception:


    Code:
    java.lang.IllegalArgumentException at oracle.xml.jaxp.JXTransformer.setOutputProperty(JXTransformer.java:619)
    	at org.springframework.web.servlet.view.xslt.AbstractXsltView.doTransform(AbstractXsltView.java:394)
    	at org.springframework.web.servlet.view.xslt.AbstractXsltView.doTransform(AbstractXsltView.java:351)
    	at org.springframework.web.servlet.view.xslt.AbstractXsltView.renderMergedOutputModel(AbstractXsltView.java:304)
    	at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
    	at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1051)
    	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817)
    	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:727)
    	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:396)
    	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:350)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
    	at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
    	at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
    	at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
    	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
    	at java.lang.Thread.run(Unknown Source)
    Any help would be greatly appreciated,

    Dustin

  2. #2
    Join Date
    Aug 2004
    Location
    Sydney
    Posts
    503

    Default

    The Oracle parser is rubbish. Try Xerces/Xalan before coming to any conclusions about any possible bugs in your code.

    We've just done much hair pulling trying to work out why a SAX XMLReader wouldn't work with Oracle's amusing, non-standard implementation.

    If you're using OC4J, you can unzip the Xalan jars into the applib directory.

    If you're using 10g r3, you can follow a document (google it) to replace the Oracle parser with Xerces/Xalan.

    If you're using 904, you're up the creek.

  3. #3
    Join Date
    May 2006
    Posts
    11

    Default

    Cool, thanks, I figured out how to switch parsers, but now I am basically getting the same exception from xalan:

    Code:
    java.lang.NullPointerException
    	at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:642)
    	at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1284)
    	at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1262)
    	at org.springframework.web.servlet.view.xslt.AbstractXsltView.doTransform(AbstractXsltView.java:406)
    	at org.springframework.web.servlet.view.xslt.AbstractXsltView.doTransform(AbstractXsltView.java:351)
    	at org.springframework.web.servlet.view.xslt.AbstractXsltView.renderMergedOutputModel(AbstractXsltView.java:304)
    	at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
    	at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1051)
    	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817)
    	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:727)
    	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:396)
    	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:350)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
    	at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
    	at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
    	at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
    	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
    	at java.lang.Thread.run(Unknown Source)
    Look familiar?

    Much obliged,
    Dustin

  4. #4
    Join Date
    Aug 2004
    Location
    Sydney
    Posts
    503

    Default

    I think I've seen this before, but i'd really be digging the cobwebs out of my brain to remember.

    Try checking you're not passing null parameters to the transformer.

    e.g.

    myTransformer.setParameter("blah", someParamWhichIsNull);

    also check that you XML actually contains data. I vaguely remember I once tried printing the contents of an InputStream once and then wondered why no transform was occurring, i.e. already drained the InputStream.

    If this doesn't help, maybe post your XSLT and the Java code you use to do the transform.

  5. #5
    Join Date
    May 2006
    Posts
    11

    Default

    Yeah, I think it must be my stylesheet, because I definately am not sending an empty document. However, they stylesheet is the one from the example:

    Code:
    <?xml version="1.0"?>
    
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:template match="/">
            <html>
                <head><title>Hello!</title></head>
                <body>
    
                    <h1>My First Words</h1>
                    <xsl:for-each select="wordList/word">
                        <xsl:value-of select="."/><br />
                    </xsl:for-each> 
    
                </body>
            </html>
        </xsl:template>
    </xsl:stylesheet>
    Look good?

    Thanks,
    Dustin

  6. #6
    Join Date
    May 2006
    Posts
    11

    Default

    In the Spring reference manual they implement the abstract method createDomNode() from the AbstractXsltView class. However, I was just looking at the API and there is no such method in Spring 2.0 (it exists in Spring 1.2). I assume this is the problem I am having. Does anybody know where I can find some accurate documentation?

  7. #7
    Join Date
    May 2006
    Posts
    11

    Default

    HA HA! Triumph! I had to impliment createXsltSource() rather than createDomNode() in my subclass of AbstractXsltView. The API says that createDomNode() should work, though it only exists for backwards compatibility. However, I got the exceptions I mentioned above. I also had to change my xslt stylesheet to print out the proper words. Here is the code I changed from the example in the reference manual (this all concerns Spring 2.0).

    So rather than createDomNode() I used createXsltSource:

    Code:
    protected Source createXsltSource(Map model, String rootName, HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
    		org.jdom.Document doc = new org.jdom.Document();
            Element root = new Element("words");
            doc.setRootElement(root);
    
            List words = (List) model.get("wordList");
            for (Iterator it = words.iterator(); it.hasNext();) {
                String nextWord = (String) it.next();
                System.out.println(nextWord);
                Element e = new Element("word");
                e.setText(nextWord);
                root.addContent(e);
            }
            System.out.println("Start:");
            System.out.println(doc.toString());
            System.out.println("Stop:");
            
            Node node =  new DOMOutputter().output( doc );
            return new DOMSource(node);
    	}
    and here is the xslt:

    Code:
    <?xml version="1.0"?>
    
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output omit-xml-declaration="yes"/>
    
        <xsl:template match="/">
            <html>
                <head><title>Hello!</title></head>
                <body>
    
                    <h1>My First Words</h1>
                    <xsl:for-each select="words/word">
                        <xsl:value-of select="."/><br />
                    </xsl:for-each> 
    
                </body>
            </html>
        </xsl:template>
    
    </xsl:stylesheet>
    Thanks for your help,

    Dustin

  8. #8
    Join Date
    Aug 2004
    Location
    Sydney
    Posts
    503

    Default

    You may consider rewriting your code and use an XMLReader.

    1. Implement XMLReader, and implement the getter/setters for contentHandler, dtdHandler, entityResolver, and errorHandler.

    2. In parse (InputSource input)...

    getContentHandler().startDocument();
    AttributesImpl attrs = new AttributesImpl();
    attrs.addAttribute("", "someAttribute", "someAttribute", "string", "someValue");
    getContentHandler().startElement("", "words", "words", attrs);
    getContentHandler().endElement();
    getContentHandler().endDocument();

    ...or whatever, as required to build the necessary XML doc.

    This way, you don't have to accumulate the entire XML document in memory.

    3. Source saxSource = new SAXSource(myXmlReaderImplementation);

    and then use saxSource as you would a DOMSource.

  9. #9
    Join Date
    Dec 2005
    Posts
    269

    Default

    btw, based on my experiments I like saxon more than xalan

  10. #10
    Join Date
    May 2006
    Posts
    11

    Default

    I like your suggestion to move to a SAX processor, however, I will be pulling my xml from oracle xml db with xqueries, so the document, from my understanding, will already be loaded into memory (I suppose for large documents, I could have my xqueries format the data as it comes in). I could be wrong here however, since I am new to this. In my examples above, I pretty much just cut and pasted the example code from the spring reference manual to get this stuff working. I like to do that and build up from there.

    Perhaps if I have performance issues I will try the saxon parser - I am just glad to get something working at this point

    Thanks again for the help and suggestions,
    Dustin

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •