You will need to use valid XML for your JSP page, "<@taglib" is not
valid xml. There is an equivelent "<jsp:directive.taglib " you will
need to use. Have a look at
http://ndpsoftware.com/JSPXMLCheatSheet.html for other tags.

I think you might need to declare both the spring and jsp namespace in
the XSL, been a while since I darkened my mind with XSLT.

Interesting approuch, may I ask why you are doing it this way?

Brian


On Dec 28, 2007 7:46 PM, subzero <[EMAIL PROTECTED]> wrote:
>
> hi,
> i have created the xml and the xsl requried to transform that xsl to a
> jsp as bellow.
>
> XML:
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <profile name="Hospital">
>     <search_criteria>
>         <criteria id="latitude" display_name="Latitude">
>             <data_type format="text box">
>             </data_type>
>             <search-type>
>                 <value>direct</value>
>             </search-type>
>         </criteria>
>         <criteria id="longitude" display_name="Longitude">
>             <data_type format="text box">
>             </data_type>
>             <search-type>
>                 <value>direct</value>
>             </search-type>
>         </criteria>
>         <criteria id="hos_name" display_name="Hospital Name">
>             <data_type format="text box">
>             </data_type>
>             <search_type>
>                 <value>direct</value>
>             </search_type>
>         </criteria>
>         <criteria id="district" display_name="District">
>             <data_type format="drop down">
>                 <value>Kurunegala</value>
>                 <value>Kegalle</value>
>                 <value>Katunayake</value>
>                 <value>Kelaniya</value>
>             </data_type>
>             <search_type>
>                 <value>direct</value>
>             </search_type>
>         </criteria>
>         <criteria id="no_patients" display_name="No of patients">
>             <data_type format="text box">
>             </data_type>
>             <search_type>
>                 <value>count</value>
>             </search_type>
>         </criteria>
>         <criteria id="icu" display_name="ICU Facility">
>             <data_type format="check box">
>                 <value>Yes</value>
>             </data_type>
>             <search-type>
>                 <value>direct</value>
>             </search-type>
>         </criteria>
>     </search_criteria>
> </profile>
>
> according to my specific needs i my XSL looks as bellow:
>
>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
> version="1.0">
>
>     <xsl:template match="/">
>         <%@ taglib prefix="spring" uri="http://www.springframework.org/
> tags%>
>           <html>
>             <head>
>
>                 <title>Profile Search Page</title>
>
>                 <script type="text/javascript">
>                     <!-- create elements according to the selection
> criteria -->
>                     function addElement(){
>
>                     var x=document.getElementById("search_item");
>                     var y =document.getElementById("add");
>                     var id=x.options[x.selectedIndex].id;
>                     var name=x.options[x.selectedIndex].text;
>                     x.remove(x.selectedIndex);
>
>                     var ni = document.getElementById('query_page');
>
>                     var newdiv = document.createElement('div');
>                     newdiv.setAttribute("id","newDiv");
>
>                     <!-- call to create html to append attributes -->
>                     buildHtml(id,newdiv,name);
>                     ni.appendChild(newdiv);
>
>                     if((x.length)==0){      <!-- if all search
> criteria selected add a caption and disable the selection --
> >
>                     var item =document.createElement('option');
>                     var option = document.createTextNode("No search
> criteria left!");
>                     item.appendChild(option);
>                     item.id="no_values";
>                     x.appendChild(item);
>                     x.disabled=true;
>                     y.disabled=true;
>                     }
>
>                     <!-- check submit buttons exists or not -->
>                     var
> addElementCheck=document.getElementById("button_sub");
>                     var
> addElementCheck1=document.getElementById("button_reset");
>                     var buttonCheck =
> document.getElementById("submit");
>
>                     <!-- create submit and reset buttons if they are
> not in the form -->
>                     if((buttonCheck==null)){
>                     var subButton=document.createElement('input');
>                     var resetButton=document.createElement('input');
>                     subButton.type="submit";
>
> subButton.setAttribute("onclick","fillsubmitvalues()");
>                     subButton.value="Submit";
>                     subButton.id="submit";
>                     resetButton.type="reset";
>                     resetButton.value="Reset";
>                     addElementCheck.appendChild(subButton);
>                     addElementCheck1.appendChild(resetButton);
>                     }
>                     }
>
>                     function buildHtml(id,div,name){        <!--
> create the html attributes according to the selection and append to
> the existing html -->
>
>                     var table
> =document.getElementById("selectedItems");
>                     var tr =
> table.insertRow(-1);
>                     var td1 = tr.insertCell(0);
>                     var td2 = tr.insertCell(1);
>                     var td3 =tr.insertCell(2);
>                     var check;
>                     var type;
>                     var item;
>                     var js_type;
>                     var type_length;
>                     var element_type;
>                     var input_type;
>
>                     <xsl:for-each select="//search_criteria/criteria">
>                         <xsl:text>check='</xsl:text><xsl:value-of
> select="./@id"/><xsl:text>';</xsl:text>
>
>                         if((check .match(id))!=null){
>
>                         <xsl:text>type='</xsl:text><xsl:value-of
> select="data_type/@format"/><xsl:text>';</
> xsl:text>
>
>
> js_type=getType(type);
>                         if(js_type.match('input')!=null){
>                         type_length=0;
>                         type_length=js_type.length;
>                         element_type =js_type.substr(0,5);
>
> input_type=js_type.substr(6,type_length);
>                         item=document.createElement(element_type);
>                         item.type=input_type;
>                         item.id=id;
>                         td2.appendChild(item);
>                         if(input_type.match('checkbox')!=null){
>                         var text_value;
>                         <xsl:text>text_value='</xsl:text><xsl:value-of
> select="data_type/value"/><xsl:text>';</
> xsl:text>
>                         var text =
> document.createTextNode(text_value);
>                         item.value=text_value;
>
> td2.appendChild(text);
>                         td2.insertBefore(item,text);
>                         }
>                         }
>                         else {
>                         item=document.createElement(js_type);
>                         item.id=id;
>                         item.setAttribute("width","50%");
>                         <xsl:for-each select="data_type/value">
>                             var option =
> document.createElement('option');
>                             var text_value;
>                             <xsl:text>text_value='</
> xsl:text><xsl:value-of select="."/><xsl:text>';</xsl:text>
>                             option.value=text_value;
>                             var text =
> document.createTextNode(text_value);
>                             option.appendChild(text);
>                             item.appendChild(option);
>                         </xsl:for-each>
>                         td2.appendChild(item);
>                         }
>
>                         var add_button =
> document.createElement('input');
>                         add_button.type="button";
>                         add_button.value="Remove";
>
> add_button.setAttribute("onclick","addback(this)");
>                         td3.appendChild(add_button);
>                         td1.innerHTML=name+":
> ";
>                         }
>                     </xsl:for-each>
>
>                     colorForm(table);
>
>                     }
>
>                     <!-- call to add the elements back to the
> selection criteria when it is deleted for the search form -->
>                     function addback(r){
>
>                     var
> i=r.parentNode.parentNode.rowIndex;
>                     var x = document.getElementById("search_item");
>                     var y =document.getElementById("add");
>
>                     if(x.disabled==true){
>                     x.disabled=false;
>                     y.disabled=false;
>                     var
> remove_label=document.getElementById("no_values");
>                     x.removeChild(remove_label);
>
>                     }
>
>                     var
> table_rows=r.parentNode.parentNode.parentNode.rows.length;
>
>
>                     var item = document.createElement('option');
>                     var text
> =document.createTextNode(r.parentNode.parentNode.parentNode.rows[i].cells[0].innerHTML.replace(/:/,"
> "));
>
> item.id=r.parentNode.parentNode.parentNode.rows[i].cells[1].firstChild.id;
>                     item.appendChild(text);
>                     x.appendChild(item);
>                     var table
> =document.getElementById("selectedItems");
>                     table.deleteRow(i);
>
>                     if(table_rows==1){
>                     var
> addElementCheck=document.getElementById("button_sub");
>                     var
> addElementCheck1=document.getElementById("button_reset");
>                     addElementCheck.innerHTML="";
>                     addElementCheck1.innerHTML="";
>                     }
>                     colorForm(table);
>                     }
>
>                     function getType(type){
>                     switch(type){
>                     case 'text box':
>                     return "input-text";
>                     break;
>                     case 'check box':
>                     return "input-checkbox";
>                     break;
>                     default:
>                     return "select";
>                     break;
>                     }
>                     }
>
>                     function fillsubmitvalues(){
>                     var submit_table
> =document.getElementById("selectedItems");
>                     var submit_text="";
>                     var
> setHidden=document.getElementById("submitValues");
>
>                     for(var i=0;i&lt;submit_table.rows.length;i++){
>                     submit_text=submit_text
> +"("+submit_table.rows[i].cells[1].firstChild.id+",";
>                     submit_text=submit_text
> +submit_table.rows[i].cells[1].firstChild.value
> +")";
>                     }
>                     setHidden.setAttribute("value",submit_text);
>                     }
>
>
>                     function validate(){
>                     var submit_table
> =document.getElementById("selectedItems");
>                     var submit_text="";
>                     var check=true;
>                     for(var i=0;i&lt;submit_table.rows.length;i++){
>
> submit_text=submit_table.rows[i].cells[1].firstChild.value;
>
> if(submit_table.rows[i].cells[1].firstChild.type=="checkbox"){
>                     var checkbox =
> submit_table.rows[i].cells[1].firstChild;
>                     if((checkbox.checked) !=true)
> {
>                     check=false;
>                     if(submit_table.rows.length==1){
>                     alert("Please select the check box or remove!");
>                     }
>                     else {
>                     alert("Please give values to selected searching
> criterias!");
>                     }
>                     break;
>                     }
>                     }
>                     else {
>                     if(submit_text==""){
>                     check=false;
>                     alert("Please give values to selected searching
> criterias!");
>                     break;
>                     }
>                     }
>                     }
>
>                     return check;
>                     }
>
>                     function colorForm(table){
>
>                     for(var i=0;i&lt;table.rows.length;i++){
>                     var td=table.rows[i];
>                     if((i%2)!='0'){
>                     td.setAttribute("bgcolor","#FAFAD2");
>                     }
>                     else {
>                     td.setAttribute("bgcolor","#D3D3D3");
>                     }
>                     }
>                     }
>                 </script>
>
>             </head>
>             <body>
>                 <h2><xsl:value-of select="//@name"/> Search Page</h2>
>                 <p>Select the requried searching criteria</p>
>                 <table border="0">
>                     <tr>
>                         <td>
>                             <select id="search_item">
>                                 <xsl:for-each select="//
> search_criteria/criteria">
>
> <option>
>                                         <xsl:attribute name="id">
>                                             <xsl:value-of select="./
> @id"/>
>                                         </xsl:attribute>
>                                         <xsl:value-of select="./
> @display_name"/>
>                                     </
> option>
>                                 </xsl:for-each>
>                             </select>
>                         </td>
>                         <td><input type="button" id="add" value="Add"
> onclick="addElement()"/>
>                         </td>
>                     </tr>
>                 </table>
>                 <br/>
>                 <div id="query_page">
>                     <form action="#" method="post" id="search_form"
> onsubmit="return validate()">
>                         <table border="0" id="selectedItems"></table>
>                         <div>
>                             <table border="0" id="buttons">
>                                 <tr
> align="center">
>                                     <td id="button_sub" ></td>
>                                     <td id="button_reset"></td>
>                                 </tr>
>                             </table>
>                         </div>
>                         <spring:bind
> path="searchCriteria.criteria">]]>
>                         <input type="hidden" id="submitValues"
> value="test"/>
>                         <spring:bind>
>                     </form>
>                 </div>
>             </body>
>         </html>
>     </xsl:template>
> </xsl:stylesheet>
>
>
> in here the xsl+xml=>jsp conversion is done by following Java code;
>
> package lif.webclient.controller.extract;
>
> import java.io.File;
> import java.io.FileInputStream;
> import java.io.FileNotFoundException;
> import java.io.FileOutputStream;
> import java.io.IOException;
> import java.io.InputStream;
> import java.io.InputStreamReader;
>
> import javax.xml.parsers.DocumentBuilder;
> import javax.xml.parsers.DocumentBuilderFactory;
> import javax.xml.parsers.ParserConfigurationException;
> import javax.xml.transform.Result;
> import javax.xml.transform.Source;
> import javax.xml.transform.Transformer;
> import javax.xml.transform.TransformerConfigurationException;
> import javax.xml.transform.TransformerException;
> import javax.xml.transform.TransformerFactory;
> import javax.xml.transform.dom.DOMSource;
> import javax.xml.transform.stream.StreamResult;
> import javax.xml.transform.stream.StreamSource;
>
> import org.w3c.dom.Document;
> import org.xml.sax.SAXException;
>
> public class JSPCreator {
>
>         private final String XSLTRANSFORMFILE = "profile_mapping.xsl";
>         private final String XMLMAPPINGFILE = "profile_mapping.xml";
>
>         public String tomcathome;
>
>         public void transform(String profileXMLPath, String profileName){
>
>         try {
>                 createJSPDirectory(profileName);
>             FileOutputStream fileStream =  new
> FileOutputStream("output file path"+"output file name");
>
>             InputStream in = this.getClass().getResourceAsStream("xsl
> file");
>             InputStreamReader xsltStream = new InputStreamReader(in);
>
>             Source xsltSource = new StreamSource(xsltStream);
>
>             TransformerFactory transformerFactory =
> TransformerFactory.newInstance();
>
>             Transformer transformer =
> transformerFactory.newTransformer(xsltSource);
>
>             //cdxml.xml --> dom tree.
>             FileInputStream xmlStream =new FileInputStream("xml
> file");
>
>             DocumentBuilder documentBuilder =
> DocumentBuilderFactory.newInstance().newDocumentBuilder();
>             Document doc = documentBuilder.parse(xmlStream);
>
>
>
>             Source xmlSource = new DOMSource(doc);
>             Result result = new StreamResult(fileStream);
>             transformer.transform(xmlSource, result);
>
>
>             fileStream.flush();
>             fileStream.close();
>
>         } catch (FileNotFoundException e) {
>             e.printStackTrace();
>         } catch (IOException e) {
>             e.printStackTrace();  //To change body of catch statement
> use File | Settings | File Templates.
>         } catch (TransformerConfigurationException e) {
>             e.printStackTrace();  //To change body of catch statement
> use File | Settings | File Templates.
>         } catch (ParserConfigurationException e) {
>             throw new RuntimeException(e);
>         } catch (TransformerException e) {
>             e.printStackTrace();  //To change body of catch statement
> use File | Settings | File Templates.
>         } catch (SAXException e) {
>             e.printStackTrace();  //To change body of catch statement
> use File | Settings | File Templates.
>         }
>
>
>     }
>
> }
>
>
> but i can't get the spring tag by just adding the "<%@ taglib ...%>"
> tags coz it gives saxon 6.5 error.... because of wrong xsl file
> format. Can any one please help on this to get this job done.......
> thanks,
> sub zero
> >
>



-- 
Brian Silberbauer
Consultant

+27 (0)83 566 2705
skype: brian.silberbauer
http://www.linkedin.com/in/briansilberbauer

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CTJUG Tech" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.co.za/group/CTJUG-Tech?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to