This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes Combining existing data with xml in a transform Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Combining existing data with xml in a transform" Watch "Combining existing data with xml in a transform" New topic
Author

Combining existing data with xml in a transform

Thomas Kennedy
Ranch Hand

Joined: Jan 20, 2008
Posts: 137
I have a requirement to do a bunch of enrollment forms in the context of jsp. The same questions appear on many forms, but sometimes with different labels, or different options. So the same question could be marked up with one xsl in form A but another xsl in form B. So I plan to implement each question as an xml file:

question_001.xml



question_017.xml



colors.xml



The xsl will turn the question into an input, or a checkbox or a textarea and so on.

My jsp will look something like this:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>

<html>
<head>
<title>XYZ enrollment</title>
</head>
<body>

<div id="part1" class="question">
<c:import url="question_001.xml" var="question_001"/>
<c:import url="question_001.xsl" var="question_001.xsl"/>
<x:transform xml="${question_001}" xslt="${question_001.xsl}"/>
</div>

<div id="part2" class="boilerplate">
<c:import url="http://localhost:8080/boilerplate_001.xml" var="boilerplate_001"/>
<c:import url="http://localhost:8080/boilerplate_001.xsl" var="boilerplate_001.xsl"/>
<x:transform xml="${boilerplate_001}" xslt="${boilerplate_001.xsl}"/>
</div>

<div id="part3" class="question">
<c:import url="question_002.xml" var="question_002"/>
<c:import url="question_002.xsl" var="question_002.xsl"/>
<x:transform xml="${question_002}" xslt="${question_002.xsl}"/>

<c:import url="question_003.xml" var="question_003"/>
<c:import url="question_003.xsl" var="question_003.xsl"/>
<x:transform xml="${question_003}" xslt="${question_003.xsl}"/>
</div>

</body>
</html>

Response data will be captured in xml columns, so I have the option of exposing existing data through the view as xml, or Strings or lists or whatever.

What I don't know how to do is combine existing response data into the markup in some cases. For input fields that's easy, I can have the transform spit out the markup necessary to retrieve the field value from the view. What I don't understand is how to populate things like checkboxes. For example how can my transform know whether to insert the checked="checked" attribute if, for a <question> whose options are RED BLUE GREEN and whose presentation should be checkbox format, the existing data says the user selected GREEN?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18168
    
    8

Usually you do that by passing parameters to the transform. I'm not sure if you can pass parameters to the transform via JSTL -- after a quick look around the web it looks like you can't, but you should do a more thorough look than what I did.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18168
    
    8

I suppose you could make it work by having a servlet which generated a suitable XSL transformation based on input parameters, instead of a fixed transformation like you have there, but if I found myself going down that road I would think hard about whether there was a different approach.
Thomas Kennedy
Ranch Hand

Joined: Jan 20, 2008
Posts: 137
Looking over this again I think most questions could be handled as well with tag files. A given question mat have different text on different forms but I think that can be handled adequately with tags. A completely different skin on the same question is more of an edge case. The boilerplate almost certainly needs transforms, but does not need params.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Combining existing data with xml in a transform
 
Similar Threads
parameters to XSL from x:transform JSTL tag
Royally stumped with jstl <c:if test of request.method
Encountered an unknown type while processing 'xslt' attribute
What can be the problem with this relative path?
Exception -- Content is not allowed in prolog