Skip to main content
IBM  
Shop Support Downloads
IBM Home Products Consulting Industries News About IBM
IBM developerWorks : XML : Education - Tutorials
Tootomatic with Java 2 v1.4.2_05, and a Self-test feature
PDF (letter)PDF (A4)Javascript e-mail it pop-up
Main menuSection menuFeedbackNext
4. Self-Test Feature
  


Adding Self-Test xsl:template page 1 of 3


to the build-individual-panels.xsl file, ADD

<xsl:template match="self-test" mode="build-individual-panels" >
<script type='text/javascript'>
<![CDATA[
<!--
function replaceSpan]]><xsl:value-of select='@span'/><![CDATA[(displayedText,spanNumber){
var newSpan = document.createElement("span");
var newText = document.createTextNode(displayedText);
newSpan.appendChild(newText);
var para = document.getElementById("area"+spanNumber);
var spanElm = document.getElementsByTagName("span")[spanNumber];
var replaced = para.replaceChild(newSpan,spanElm);
}
var testtext = "<form><center><u>]]><xsl:value-of select='@question'/><![CDATA[</u></center>";
testtext += "<input type='radio' name='c' value='' onClick='replaceSpan]]><xsl:value-of select='@span'/><![CDATA[(
&#34;]]><xsl:value-of select='@answer1'/><![CDATA[&#34;,&#34;]]><xsl:value-of select='@span'/><![CDATA[&#34;)' />]]><xsl:value-of select='@choice1'/><![CDATA[<br/>";
testtext += "<input type='radio' name='c' value='' onClick='replaceSpan]]><xsl:value-of select='@span'/><![CDATA[(
&#34;]]><xsl:value-of select='@answer2'/><![CDATA[&#34;,&#34;]]><xsl:value-of select='@span'/><![CDATA[&#34;)' />]]><xsl:value-of select='@choice2'/><![CDATA[<br/>";
testtext += "<input type='radio' name='c' value='' onClick='replaceSpan]]><xsl:value-of select='@span'/><![CDATA[(
&#34;]]><xsl:value-of select='@answer3'/><![CDATA[&#34;,&#34;]]><xsl:value-of select='@span'/><![CDATA[&#34;)' />]]><xsl:value-of select='@choice3'/><![CDATA[<br/>";
testtext += "<input type='radio' name='c' value='' onClick='replaceSpan]]><xsl:value-of select='@span'/><![CDATA[(
&#34;]]><xsl:value-of select='@answer4'/><![CDATA[&#34;,&#34;]]><xsl:value-of select='@span'/><![CDATA[&#34;)' />]]><xsl:value-of select='@choice4'/><![CDATA[<br/>";
testtext += "<center><table><tr><td><font color='#ff0000'>";
testtext += "<div id='area]]><xsl:value-of select='@span'/><![CDATA['><span></span></div></font></td></tr></table></center></form>";
document.write(testtext);
// -->
]]>
</script>
</xsl:template>

The complexities involved with parsing CDATA, Javascript, and Entities are beyond the scope of this discussion.

Avoid the "white-space" problems involved with copying the above code and Cut and Paste from the zipped Text files. The above xsl:template code for the build-individual-panels.xsl file is included in the File Modifications folder


Main menuSection menuFeedbackNext
About IBM | Privacy | Legal | Contact