• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Combining existing data with xml in a transform

 
Thomas Kennedy
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic