PDA

View Full Version : basic xml/xslt help


sticky
Oct 5th, 2005, 07:35 AM
Hi
I am very new to Spring. I need to output HTML via an xml file that is to be passed to an xslt sheet. The xml will have some nodes changed/added depending upon data from the data model.

Now, I have read the documentation regarding xsltView and googled a lot but I can't quite grasp how it all fits together, especially to the point of outputting the HTML to the browser. I know I have not provided a lot of detail, because at present there isn't a great deal, but I would be very grateful if someone could point me in the direction of some basic examples of outputting html from xml using Spring.

thank you
Laing

davison
Oct 5th, 2005, 09:42 AM
which bit of the documentation wasn't clear? It gives a short, concise but complete example of using XSLT in Spring. If you can supply information about what you have so far tried to do, that would help.

Regards,

sticky
Oct 5th, 2005, 11:40 AM
which bit of the documentation wasn't clear? It gives a short, concise but complete example of using XSLT in Spring. If you can supply information about what you have so far tried to do, that would help.

Regards,

Hi
Well I don't really know where to start. My app so far has an application context file that maps out all the data connections and DataAccessObjects etc.

I then have a DispacherServlet loaded at startup with an xml file that contains the various mappings e.g.

<entry key="/projects.html">
<ref bean="listProjectsController" />
</entry>

the relevant controller looking like this:

public class ListProjectsController extends AbstractController {

private ProjectService projectService;

public void setProjectService(ProjectService projectService) {
this.projectService = projectService;
}

protected ModelAndView handleRequestInternal(HttpServletRequest request,
HttpServletResponse response) throws Exception {

Map model = new HashMap();

model.put("projects", projectService.getAllProjects());

return new ModelAndView("projects", "model", model);
}

}

Then a .jsp outputs the data returned in the model. I am sure this is all old hat to you.

The next part of the app requires an xml file to be output as html and AbstractXsltView looked like what was needed and from the example I can see that an xml file has been created and from that a DOM but where does this go? The controllers I have used thus far have output a model to a jsp file. The example returns a Dom as far as I can make out but what picks it up?

Sorry if I am being dumb!

davison
Oct 5th, 2005, 01:41 PM
The example returns a Dom as far as I can make out but what picks it up?

Sorry if I am being dumb!
If you read a little further down the docs at http://www.springframework.org/docs/reference/view.html#view-xslt you should see a small code sample showing views.properties.

This configure your view resolver - that's where the XSLT location is defined that your view will use to transform the DOM (or Source).

Have a go actually coding that example in a small test app, I think that should help to make it a little clearer for you. Post back with any more queries.

Regards,

sticky
Oct 6th, 2005, 08:23 AM
If you read a little further down the docs at http://www.springframework.org/docs/reference/view.html#view-xslt you should see a small code sample showing views.properties.

Yes I had read it but now the penny has finally dropped doh! :oops:

I think I was expecting it to be more complicated - it is, in fact, very impressive.

After some fiddling with view resolvers et al I have the example up and working and I can take it from there.

thanks for your help

Laing