Hi Eric, I was able to convert XML to VM file using turbine's TurbineXSLTService. The Screen class code, xml and xsl file ares in the attached docuemnts. However I have no idea how I can populate the components when VM file is displayed. I would like to take the approach you sugeested but I have not used DOM4J before, can you send me sample code how to go about.
regards Keshava Murthy. S ----- Original Message ----- From: "Eric Emminger" <[EMAIL PROTECTED]> To: "Turbine Users List" <[EMAIL PROTECTED]> Sent: Thursday, June 12, 2003 6:38 PM Subject: Re: Generating VM from XML file dynamically > Keshava > > Keshava Murthy wrote: > > I am giving below a part of xml file - > > > > <solution> > > <stat>Alkaline Lysis Solution</stat> > > <date type="cb" name="MI01" table="mas_solutions" col="soln_prepdt" > > where="soln_name='Alkaline Lysis Solution'"> </date> > > </solution> > > > > When this is converted to VM file, the component should be a dropdown > > menu(type="cb" --> cb indicates it is Combo box) and name of the component > > should be MI01 and it should have data populated from "soln_prepdt" column > > from "mas_solutions" table where "soln_name" ='Alkaline Lysis Solution'. > > Interesting. Here's how I did something similar. > > Using DOM4J, load your XML file as a Document and put it in the Velocity > context. In your VM (Velocity template), step through the Document, > creating the HTML you need. > > Eric > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > >
Test.java
Description: java/
<?xml version="1.0" encoding="UTF-8" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <!-- This version of prot.xsl converts a xml document into HTML with proper controls in the correct places. If a field is found in 'methods', it checks whether a TB or a CB or a LBshould be called - and inserts the correct control However, it does not choose the contents in the control to be displayed. i.e. all comboboxes have the same content. All textboxes have the same content. This version also names the control widgets as per the name attribute defined in the source XML. Additionally, for input samples, the XSL makes a table and puts 2 listboxes and 2 buttons there. The generation of this is STATIC. i.e., whenever it finds an element with name="sample" inside the element "materials", the table with the contents are displayed. IT DOES NOT MATTER what control type is defined in the XML, the xslt produces the same output!! --> <xsl:template match="/"> <html> <body> <form name ="protocol" method ="post" action ="$link.setPage("Protocol.vm").setAction("SQLProtocol")" > <h2>Protocol name:</h2> <xsl:apply-templates select="/protocol/name" /> <h3>Materials</h3> <xsl:apply-templates select="/protocol/materials" /> <h3>Methods</h3> <xsl:apply-templates select="/protocol/methods" /> </form> </body> </html> </xsl:template> <xsl:template match="name"> <xsl:value-of select="." /><p/> </xsl:template> <!-- Template to fill in the materials --> <xsl:template match="materials"> <h4>Solutions</h4> <xsl:for-each select="solution"> <xsl:for-each select="*"> <xsl:call-template name="chooser1"/> <!-- find out whether a static or control field is to be output --> </xsl:for-each> </xsl:for-each> <h4>Solvents</h4> <xsl:for-each select="solvent"> <xsl:for-each select="*"> <xsl:call-template name="chooser1"/><!-- find out whether a static or control field is to be output --> </xsl:for-each> </xsl:for-each> <xsl:for-each select="other"> <h4>Other materials </h4> <xsl:for-each select="*"> <xsl:call-template name="chooser1"/><!-- find out whether a static or control field is to be output --> </xsl:for-each> </xsl:for-each> <xsl:for-each select="media"> <xsl:for-each select="*"> <xsl:call-template name="chooser1"/><!-- find out whether a static or control field is to be output --> </xsl:for-each> </xsl:for-each> <xsl:for-each select="sample"> <!-- This is a static template which outputs a table with 2 lb's and 2 buttons. --> <h4>Input Samples</h4> <table><tr> <td nowrap="true"><select name="select" size="10" multiple="true" style="width:150px;"> <option>Sample1</option> <option>Sample3</option> <option>Sample4</option> <option>Sample6</option> </select></td> <td align="center" valign="middle" nowrap="true"> <table width="70"> <tr> <td><input type="button" name='Submit4' value='Add'></input></td> </tr> <tr> <td><input type="button" name='Submit5' value='Remove'></input></td> </tr> </table> </td> <td nowrap="true"><select name="select2" size="10" style="width:150px;"> <option>Sample2</option> <option>Sample5</option> </select></td> </tr></table> <!-- <xsl:call-template name="cb"/> <input type="submit" name="Submit4" value="Add" style="width:70px;"> <xsl:call-template name="lb"/><p/> --> </xsl:for-each> </xsl:template> <xsl:template name="samples"> <xsl:for-each select="*"> Input Samples <xsl:call-template name="cb"/> <xsl:call-template name="lb"/><p/> </xsl:for-each> </xsl:template> <!-- Template to fill in methods--> <xsl:template match="methods"> <xsl:apply-templates select="line"/> </xsl:template> <!-- Template to fill in lines in the method--> <xsl:template match="line"> <p/> <xsl:value-of select="@ln_no"/><xsl:text>. </xsl:text> <xsl:for-each select="*"> <xsl:call-template name="chooser"/> </xsl:for-each> </xsl:template> <!-- chooser template Find out what kind of element has been encountered - static or control widget. And apply the corresponding template --> <xsl:template name="chooser"> <xsl:choose> <xsl:when test="name()='stat'"><xsl:value-of select="text()"/><xsl:text> </xsl:text> </xsl:when> <xsl:when test="@type='tb'"> <xsl:call-template name="tb"> <xsl:with-param name="name" select="@name" /> </xsl:call-template> </xsl:when><!-- In this test condition, "name()='field'" would also work--> <xsl:when test="@type='cb'"> <xsl:call-template name="cb"> <xsl:with-param name="name" select="@name" /> </xsl:call-template> </xsl:when><!-- but would also match controls of type cb and lb --> <xsl:when test="@type='lb'"> <xsl:call-template name="lb"> <xsl:with-param name="name" select="@name" /> </xsl:call-template> </xsl:when> <xsl:otherwise> no matching control found </xsl:otherwise> </xsl:choose> </xsl:template> <!-- Same as chooser, but puts a CR-LF at the end of the insertion --> <xsl:template name="chooser1"> <xsl:choose> <xsl:when test="name()='stat'"><xsl:value-of select="text()"/><xsl:text> </xsl:text> </xsl:when> <xsl:when test="@type='tb'"> <xsl:call-template name="tb"> <xsl:with-param name="name" select="@name" /> </xsl:call-template><p/> </xsl:when><!-- In this test condition, "name()='field'" would also work--> <xsl:when test="@type='cb'"> <xsl:call-template name="cb"> <xsl:with-param name="name" select="@name" /> </xsl:call-template><p/> </xsl:when><!-- but would also match controls of type cb and lb --> <xsl:when test="@type='lb'"> <xsl:call-template name="lb"> <xsl:with-param name="name" select="@name" /> </xsl:call-template><p /> </xsl:when> <xsl:otherwise> no matching control found </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template name="cb"> <!-- Insert a combo box --> <!-- this is called by chooser and by chooser1 --> <xsl:param name="name">xxx</xsl:param> <select name= "{$name}" style="width:150px;"> <option> </option> <option> </option> </select> </xsl:template> <xsl:template name="tb"> <!-- Insert a textbox --> <xsl:param name="name">xxx</xsl:param> <input name="{$name}" type="text" size="3" /> </xsl:template> <xsl:template name="lb"> <!-- Insert a listbox --> <xsl:param name="name">xxx</xsl:param> <select name="{$name}" size="10" style="width:150px;"> <option>Saurav</option> <option>Rakesh</option> <option>Sebastin</option> <option>Suresh</option> </select> </xsl:template> </xsl:stylesheet>
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="prot_v1_2.xsl" ?>
<protocol>
<name>Name of the protocol</name>
<materials>
<solution><stat>Alkaline Lysis Solution</stat><date type="cb" name="MI01" table="mas_solutions" col="soln_prepdt"
where="soln_name='Alkaline Lysis Solution'"> </date> </solution>
<other ><stat>Antibiotic for plasmid selection</stat><name type="tb" name="MI02"> </name> </other>
<solvent ><stat>Ethanol</stat> <batch type="cb" name="MI03" table="mas_solvents" col="solv_batchno"
where="soln_name='Ethanol'"></batch></solvent>
<solvent ><stat>Isopropanol</stat> <batch type="cb" name="MI04" table="mas_solvents" col="solv_batchno"
where="soln_name='Isopropanol'"></batch></solvent>
<media ><stat>Media</stat><date type="cb" name="MI05" table="mas_solutions" col="soln_prepdt"
where="soln_name='media'"></date></media>
<sample >
<stat>Sample </stat>
<sample-list type="lb" name= "MS01" table="mas_samples" col="some_col" where="sampletype ='DNA'"></sample-list>
<selected-samples type ="lb" name="MS02"></selected-samples>
</sample>
</materials>
<methods>
<line ln_no="1"><stat>Inoculated </stat><field type="tb" name="MA01P01" seq="1">5</field><stat> ml of medium containing the
antibiotic with a single colony of transformed bacteria. Incubated the culture overnight at </stat><field type="tb"
name="MA01P02" seq="2">6</field> <stat>degrees C with vigorous shaking.</stat>
</line>
<line ln_no="2"><stat>Centrifuged </stat><field type="tb" name="MA02P01" seq="3">7</field><stat> ml of the culture at 4
degrees C</stat></line>
<line ln_no="3"><stat>Aspirated the medium after centrifugation</stat></line>
<line ln_no="4"><stat>(Optional) Added an equal volume of xyz. Mixed the organic and aqeuous
phases by vortexing and then centrifuged the emulsion at </stat><field type="tb" name="MA04P01" seq="4">8</field><stat> rpm. Transferred the aqeuous
upper layer to a fresh tube.</stat></line>
<line ln_no="5"><stat>Recovery of Plasmid DNA</stat></line>
<line ln_no="6"><stat>Precipitated nucleic acids from the supernatant by adding 2 volumes of
ethanol at room temperature. Mixed the solution by vortexing and then allowed the mixture to stand for </stat><field type="tb"
name="MA06P01" seq="5">9</field><stat> minutes at room temperature</stat></line>
<line ln_no="7"><stat>Aspirated the supernatant and stood the tube in an inverted position on a
paper tissue. Additional drops of fluid adhering to the walls of the tube were removed by a disposable pipette tip.
</stat><field type="tb" name="MA07P01" seq="6">10</field></line>
</methods>
<gen-samples>
<sample>
<id >Sample ID <sample-id type="tb" name="SampleID"></sample-id></id>
<sample-type >Sample type <sampletype-list type="cb" name="SampleType" table="sampletype"
col="name"></sampletype-list></sample-type>
</sample>
</gen-samples>
</protocol>
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
