Hi there,
I have a very simple schema where each node requiring HTML output contains 7 possible numerical variables (all within nodes N1 - N13). I need to output text and image content according to the number within each node. Below is a sample of my schema:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="results.xsl"?>
<Alias xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" Name=\"d3b704a9730d4e6b8420187f0384cab5\">
<Age>40</Age>
<BMI>28.98</BMI>
<HipToWaist>0.9</HipToWaist>
<Height>1.93</Height>
<Weight>107.96</Weight>
<N1>5</N1>
<N2>6</N2>
<N3>3</N3>
<N4>5</N4>
<N5>3</N5>
<N6>1</N6>
<N7>3</N7>
<N8>5</N8>
<N9>7</N9>
<N10>4</N10>
<N11>7</N11>
<N12>7</N12>
<N13>7</N13>
</Alias>
Having read a few other forums I am slightly confused as to the cleanest way to output the html. This is an example using <xsl:when> and <xsl:choose> for a single node but would be applicable to all nodes.
<xsl:for-each select="Alias/N1">
<xsl:choose>
<xsl:when test="N1 >0 <2">
<div class="result_img"><img src="images/results/n1/score_02.jpg" border="0" alt="" /></div>
<h3>Critical</h3>
<p>Your score indicates bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla</p>
</xsl:when>
<xsl:when test="N1 >1 <3">
<div class="result_img"><img src="images/results/n1/score_02.jpg" border="0" alt="" /></div>
<h3>Very Low</h3>
<p>Your score indicates bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla</p>
</xsl:when>
<xsl:when test="N1 >2 <4">
<div class="result_img"><img src="images/results/n1/score_03.jpg" border="0" alt="" /></div>
<h3>Low</h3>
<p>Your score indicates bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla</p>
</xsl:when>
<xsl:when test="N1 >3 <5">
<div class="result_img"><img src="images/results/n1/score_04.jpg" border="0" alt="" /></div>
<h3>Moderate</h3>
<p>Your score indicates bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla</p>
</xsl:when>
<xsl:when test="N1 >4 <6">
<div class="result_img"><img src="images/results/n1/score_05.jpg" border="0" alt="" /></div>
<h3>Good</h3>
<p>Your score indicates bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla</p>
</xsl:when>
<xsl:when test="N1 >5 <7">
<div class="result_img"><img src="images/results/n1/score_06.jpg" border="0" alt="" /></div>
<h3>Very Good</h3>
<p>Your score indicates bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla</p>
</xsl:when>
<xsl:when test="N1 >6 <8">
<div class="result_img"><img src="images/results/n1/score_07.jpg" border="0" alt="" /></div>
<h3>Excellent</h3>
<p>Your score indicates bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla</p>
</xsl:when>
<xsl:otherwise>
<h3>It was not possible to calculate your score. Perhaps you forgot to fill in all question fields</h3>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
For me this looks pretty bloated but being a beginner in xslt I thought I’d canvas some opinion before proceeding any further. Any advice and help is most appreciated.
Many thanks