Announcement Announcement Module
Collapse
No announcement yet.
XsltView configuration example? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • XsltView configuration example?

    I'm stuck trying to get an XsltView set up. AbstractXsltView is deprecated, and the documentation doesn't seem to be updated to reflect this.

    A simple end-to-end example would be great.

    Thanks!

  • #2
    Got it working. For the benefit of others:

    XsltView
    "The XSLT Source object is supplied as a parameter in the model and then detected during response rendering."

    This means the XML you wish to transform should be passed in the model.

    "Users can either specify a specific entry in the model via the sourceKey property [....]"

    That's what I did. I create a Source object and put it in the model with the specified sourceKey string (in my case "xml").

    To specify the XSL to be used, I had to set it as the url value.

    In a view.properties file, I have the following:
    stuff.(class)=com.example.ui.XsltViewImpl
    stuff.url=http://localhost/xsl/stuff.xsl
    stuff.sourceKey=xml

    So one could create different entries, just changing the high level qualifier and url to allow the controller to call on different transforms for different types, i.e.:

    things.(class)=com.example.ui.XsltViewImpl
    things.url=http://localhost/xsl/things.xsl
    things.sourceKey=xml

    Currently my XsltViewImpl file is almost empty; I'm not overriding any methods. I guess I could just use the base XsltView class right now.

    Code:
    // in the controller
    	protected ModelAndView handleRequestInternal(HttpServletRequest request,
    			HttpServletResponse response) throws Exception {
    //...
    		Source s = new StreamSource(new StringReader(xmlFile));
    
    		Map model = new HashMap();
    		model.put("xml", s);
    
    		return new ModelAndView("stuff", model);
    	}

    Comment


    • #3
      do you still happen to have the full example of this?

      I am trying like hell to put together a simple spring application using xsl, but my little brain is simply not up for the task.

      Is there a good example out there of a simple spring app using xsl? Is there a book that has this info in it?

      Comment


      • #4
        Sorry, I'm running flat out. Maybe you could post what you've tried so far and problems you've hit, and someone else could help?

        One big gotcha I hit is that if you pass anything into the XSL as a param it needs to be, for lack of the right phrase, self-contained:

        <table>
        ...
        </table>

        not:

        <tr><td>...</td></tr>
        <tr><td>...</td></tr>
        <tr><td>...</td></tr>
        <tr><td>...</td></tr>

        Comment


        • #5
          Hi Bit,

          I tried the steps that you have suggested , but am getting a runtime exception "content is allowed in prolog"
          Can you suggest in What is going wrong !!!!

          Thanks
          Pratyu

          Originally posted by bit View Post
          Got it working. For the benefit of others:

          XsltView
          "The XSLT Source object is supplied as a parameter in the model and then detected during response rendering."

          This means the XML you wish to transform should be passed in the model.

          "Users can either specify a specific entry in the model via the sourceKey property [....]"

          That's what I did. I create a Source object and put it in the model with the specified sourceKey string (in my case "xml").

          To specify the XSL to be used, I had to set it as the url value.

          In a view.properties file, I have the following:
          stuff.(class)=com.example.ui.XsltViewImpl
          stuff.url=http://localhost/xsl/stuff.xsl
          stuff.sourceKey=xml

          So one could create different entries, just changing the high level qualifier and url to allow the controller to call on different transforms for different types, i.e.:

          things.(class)=com.example.ui.XsltViewImpl
          things.url=http://localhost/xsl/things.xsl
          things.sourceKey=xml

          Currently my XsltViewImpl file is almost empty; I'm not overriding any methods. I guess I could just use the base XsltView class right now.

          Code:
          // in the controller
          	protected ModelAndView handleRequestInternal(HttpServletRequest request,
          			HttpServletResponse response) throws Exception {
          //...
          		Source s = new StreamSource(new StringReader(xmlFile));
          
          		Map model = new HashMap();
          		model.put("xml", s);
          
          		return new ModelAndView("stuff", model);
          	}

          Comment

          Working...
          X