Results 1 to 5 of 5

Thread: XsltView configuration example?

  1. #1
    Join Date
    Oct 2007
    Posts
    13

    Default 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. #2
    Join Date
    Oct 2007
    Posts
    13

    Default

    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);
    	}

  3. #3

    Default

    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?

  4. #4
    Join Date
    Oct 2007
    Posts
    13

    Default

    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>

  5. #5
    Join Date
    Mar 2012
    Posts
    2

    Default

    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

    Quote 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);
    	}

Posting Permissions

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