View Full Version : viewing XML tree in JSP...
balistic
Sep 13th, 2007, 10:23 AM
Hi,
I have web page where user can enter search criteria and display the results in the same page (One single JSP page). When user enters the search criteria and hits the submit button, I call a webservice from my SimpleFormController and get an XML as a result. I would like to display this XML result by formatting with XSLT. Is there anyway to do this within the same JSP page?
Thanks in advance...
balistic
Sep 13th, 2007, 10:49 AM
Nevermind, it is a dumb question... Why not use XSLT view instead...
blazko
Feb 13th, 2008, 05:07 PM
Dear all,
please let me extend this thread with an additional question. I know there is Cocoon - but just given we have a Spring MVC app.
When using the AbstractXsltView Approach I have to deal with DOM or such. So far this is okay. However, I wonder if there is a possibility in Spring to have it anotherway.
What if I work with standard AbstractController and and JSP views the "classic" way.
I render XML through my JSP, is there a simple way to postprocess with XSL on the server side then? I am using this Viewresolver:
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewR esolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
... so, is there a possibility to invoke server-side XSL processing just after the JSTL view did its job?
I would like to use a Spring mechanism and if possible not a Servlet Filter approach.
Thanks for any hint!
Regards,
Timo
balistic
Feb 14th, 2008, 12:01 PM
In handleRenderRequestInternal method, you can add you xslt view as model object... Example would be:
ModelAndView mav = new ModelAndView(view); // Your JSP View
mav.addObject("host", searchService.getHost());
mav.addObject("xml", doc); // XML Document
mav.addObject("xsltView", "WEB-INF/xsl/toc.xslt"); // XSLT View
Then in the jsp view:
<div class="listTOC">
<c:import var="xslt" url="${xsltView}"/>
<x:transform xml="${xml}" xslt="${xslt}">
<x:param name="host" value="${host}"/>
</x:transform>
</div>
And this is your XSLT view:
<?xml version="1.0"?>
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" omit-xml-declaration="yes"/>
<xsl:param name="host"/>
<xsl:template match="/">
<xsl:apply-templates select="/book" />
</xsl:template>
....
....
....
</xsl:stylesheet>
Hope this helps.
blazko
Feb 14th, 2008, 04:20 PM
Hello balistic,
thanks for your reply! If I go you right, that won't help ;)
What I mean is more a substitution for the DOM stuff in the View class. What I would like to do is to formulate my my custom XML using JSP/JSTL and afterwards, I would like to transform the result server-side with XSLT to any destination format.
The only way I can think of would be a servlet filter, but in this context I do not feel comfortable with it.
So, what I seek is somewhat a cascaded view stack / namely first a plain controller handing over to the JstlView and that result to an XSLT view / but I think this kind of chaining is more the domain of Cocoon ;)
Thanks again!
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.