difficulty with variable
Added by Anonymous over 15 years ago
Legacy ID: #7508610 Legacy Poster: Alessandro Vallin (avalli)
Hi everybody, I am trying to transform the XML file "risultati_prova.xml" using the XSL file "risultati_prova.xsl". Everything is working, except a WHEN condition in the .xsl file (lines 119-126). In those lines I'm trying to use a variable called "pusuff" (defined at line 22). I can't figure out why it doesn't work. Can you please help me? Thanks, Alex Below you can find my two files: the first one is XML, the second one XSLT. ------------------------------------------------------------------------------ <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="./risultati_prova.xsl" ?> <!DOCTYPE classe [ <!ELEMENT classe (studente+)> <!ATTLIST classe id CDATA #REQUIRED data CDATA #REQUIRED tipo (orale|scritto|vocaboli|misto|ingresso|recupero_debito|recupero_carenze) #REQUIRED totale CDATA #IMPLIED> <!ELEMENT studente (voto_scritto*,voto_orale*)> <!ATTLIST studente nome CDATA #REQUIRED cognome CDATA #REQUIRED sesso (f|m) #REQUIRED debito (no|si) #REQUIRED ripetente (no|si) #REQUIRED> <!ELEMENT voto_scritto (#PCDATA)> <!ATTLIST voto_scritto punti CDATA #IMPLIED suff (no|quasi|si) #REQUIRED note CDATA #IMPLIED> <!ELEMENT voto_orale (#PCDATA)> <!ATTLIST voto_orale suff (no|quasi|si) #REQUIRED note CDATA #IMPLIED> ]> <classe id="4LA" data="20/09/2009" tipo="scritto" totale="90"> <studente nome="Alessandro" cognome="Greco" sesso="m" debito="si" ripetente="no"> <voto_scritto punti="57" suff="si" note="">6</voto_scritto> </studente> <studente nome="Gianni" cognome="Pizzato" sesso="m" debito="no" ripetente="no"> <voto_scritto punti="62" suff="si" note="">6.5</voto_scritto> </studente> <studente nome="Erica" cognome="Abbate" sesso="f" debito="no" ripetente="si"> <voto_orale suff="quasi" note="pessima pronuncia">5.5</voto_orale> </studente> <studente nome="Giacomo" cognome="Campitelli" sesso="m" debito="no" ripetente="no"> <voto_scritto punti="79" suff="si" note="">8</voto_scritto> </studente> <studente nome="Mohammed" cognome="Kamal" sesso="m" debito="si" ripetente="no"> <voto_scritto punti="42" suff="no" note="prova ritirata">3</voto_scritto> </studente> <studente nome="Sabrina" cognome="Fedrizzi" sesso="f" debito="no" ripetente="no"> <voto_scritto punti="46" suff="quasi" note="gravi errori sui modali">5.5</voto_scritto> </studente> </classe> ------------------------------------------------------------------------------ <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <head> <title>risultati prova <xsl:value-of select="./classe/@id"/></title> </head> <body> <center> <h1><p align="center"><tt><xsl:value-of select="./classe/@id"/></tt></p></h1> <p align="center"><tt><font size="4"><u>test <xsl:value-of select="./classe/@tipo"/></u> effettuato il <xsl:value-of select="./classe/@data"/></font></tt></p> </center> <!-- tabella statistiche --> <center> <table bgcolor="#FFFFFF" border="0" cellpadding="10"> <tr> <td> <xsl:variable name="pusuff"><xsl:value-of select="(./classe/@totale)*0.6"/></xsl:variable> <font size="2"><tt>punteggio minimo per la sufficienza : <xsl:value-of select='format-number($pusuff, "##.0")'/></tt></font> <br /> <xsl:variable name="mediap"><xsl:value-of select="sum(./classe/studente/voto_scritto/@punti) div count(./classe/studente/voto_scritto)"/></xsl:variable> <font size="2"><tt>punteggio scritto medio (su <xsl:value-of select="./classe/@totale"/>) : <xsl:value-of select='format-number($mediap, "##.00")'/></tt></font> </td> <td> <xsl:variable name="medias"><xsl:value-of select="sum(./classe/studente/voto_scritto) div count(./classe/studente/voto_scritto)"/></xsl:variable> <font size="2"><tt>media classe (scritto) : <xsl:value-of select='format-number($medias, "#.00")'/></tt></font> <br /> <font size="2"><tt># studenti con voto scritto insufficiente : <font color="#EE0000"><xsl:value-of select="count (./classe/studente/voto_scritto[@suff='no'])"/></font></tt></font> <br /> <font size="2"><tt># studenti con voto scritto incerto : <font color="#FF9933"><xsl:value-of select="count (./classe/studente/voto_scritto[@suff='quasi'])"/></font></tt></font> <br /> <font size="2"><tt># studenti con voto scritto sufficiente : <font color="#33DD33"><xsl:value-of select="count (./classe/studente/voto_scritto[@suff='si'])"/></font></tt></font> </td> <td> <xsl:variable name="mediao"><xsl:value-of select="sum(./classe/studente/voto_orale) div count(./classe/studente/voto_orale)"/></xsl:variable> <font size="2"><tt>media classe (orale) : <xsl:value-of select='format-number($mediao, "#.00")'/></tt></font> <br /> <font size="2"><tt># studenti con voto orale insufficiente : <font color="#EE0000"><xsl:value-of select="count (./classe/studente/voto_orale[@suff='no'])"/></font></tt></font> <br /> <font size="2"><tt># studenti con voto orale incerto : <font color="#FF9933"><xsl:value-of select="count (./classe/studente/voto_orale[@suff='quasi'])"/></font></tt></font> <br /> <font size="2"><tt># studenti con voto orale sufficiente : <font color="#33DD33"><xsl:value-of select="count (./classe/studente/voto_orale[@suff='si'])"/></font></tt></font> </td> </tr> </table> </center> <br /> <center> <table border="1" cellpadding="5"> <!-- colonna header --> <tr> <th align="center" bgcolor="#CCFF33"><tt>#</tt></th> <th align="center" bgcolor="#CCFF33"><tt>nome</tt></th> <th align="center" bgcolor="#CCFF33"><tt>cognome</tt></th> <th align="center" bgcolor="#CCDD66"><tt>punti (su <xsl:value-of select="./classe/@totale"/>)</tt></th> <th align="center" bgcolor="#CCDD66"><tt>scritto</tt></th> <th align="center" bgcolor="#CCDD66"><tt>orale</tt></th> <th align="center" bgcolor="#DDDD33"><tt>note</tt></th> </tr> <xsl:for-each select="classe/studente"> <xsl:sort select="@cognome"/> <xsl:sort select="@nome"/> <!-- per ordinare gli studenti in base al voto (dal più basso al più alto): <xsl:sort select="voto_scritto"/> per ordinare gli studenti in base al punteggio (dal più basso al più alto): <xsl:sort select="voto_scritto/@punti"/> --> <!-- colonna # --> <tr> <xsl:choose> <xsl:when test="@debito='si'"> <td align="center" bgcolor="#9999FF"><tt><xsl:number value="position()" format="01"/></tt></td> </xsl:when> <xsl:when test="@ripetente='si'"> <td align="center" bgcolor="#FFCC99"><tt><xsl:number value="position()" format="01"/></tt></td> </xsl:when> <xsl:otherwise> <td align="center" bgcolor="#FFFFFF"><tt><xsl:number value="position()" format="01"/></tt></td> </xsl:otherwise> </xsl:choose> <!-- colonna nome --> <xsl:choose> <xsl:when test="@sesso='f'"> <td align="center"><tt><i><xsl:value-of select="./@nome"/></i></tt></td> </xsl:when> <xsl:otherwise> <td align="center"><tt><xsl:value-of select="./@nome"/></tt></td> </xsl:otherwise> </xsl:choose> <!-- colonna cognome --> <td align="center"><tt><xsl:value-of select="./@cognome"/></tt></td> <!-- colonna punteggio Gli operatori ammessi nel filtro sono: = (uguale) != (diverso) < minore di > maggiore di --> <xsl:choose> <xsl:when test="./voto_scritto/@punti<'$pusuff'"> <td align="center"><tt><font color="#DD00DD"><xsl:value-of select="./voto_scritto/@punti"/></font></tt></td> </xsl:when> <xsl:otherwise> <td align="center"><tt><xsl:value-of select="./voto_scritto/@punti"/></tt></td> </xsl:otherwise> </xsl:choose> <!-- colonna voto scritto --> <xsl:choose> <xsl:when test="./voto_scritto/@suff='si'"> <td align="center" bgcolor="#FFFFFF"><tt><font color="#33DD33"><xsl:value-of select="./voto_scritto"/></font></tt></td> </xsl:when> <xsl:when test="./voto_scritto/@suff='quasi'"> <td align="center" bgcolor="#FFFFFF"><tt><font color="#FF9933"><xsl:value-of select="./voto_scritto"/></font></tt></td> </xsl:when> <xsl:otherwise> <td align="center" bgcolor="#FFFFFF"><tt><font color="#EE0000"><xsl:value-of select="./voto_scritto"/></font></tt></td> </xsl:otherwise> </xsl:choose> <!-- colonna voto orale --> <xsl:choose> <xsl:when test="./voto_orale/@suff='si'"> <td align="center" bgcolor="#FFFFFF"><tt><font color="#33DD33"><xsl:value-of select="./voto_orale"/></font></tt></td> </xsl:when> <xsl:when test="./voto_orale/@suff='quasi'"> <td align="center" bgcolor="#FFFFFF"><tt><font color="#FF9933"><xsl:value-of select="./voto_orale"/></font></tt></td> </xsl:when> <xsl:otherwise> <td align="center" bgcolor="#FFFFFF"><tt><font color="#EE0000"><xsl:value-of select="./voto_orale"/></font></tt></td> </xsl:otherwise> </xsl:choose> <!-- colonna note --> <td align="center"> <tr><tt><xsl:value-of select="./voto_scritto/@note"/></tt></tr> <tr><tt><xsl:value-of select="./voto_orale/@note"/></tt></tr> </td> </tr> </xsl:for-each> </table> </center> <br/> <table bgcolor="#FFFFFF"> <tr> <td bgcolor="#9999FF"><font color="#9999FF">xx</font></td> </tr> </table> <font size="1"><tt>studenti con debito in inglese</tt></font> <br/><br/> <table bgcolor="#FFFFFF"> <tr> <td bgcolor="#FFCC99"><font color="#FFCC99">xx</font></td> </tr> </table> <font size="1"><tt>studenti ripetenti</tt></font> </body> </html> </xsl:template> </xsl:stylesheet> ----------------------------------------------------------------------
Replies (3)
Please register to reply
RE: difficulty with variable - Added by Anonymous over 15 years ago
Legacy ID: #7508666 Legacy Poster: penguish (penguish)
Looks like a scope problem. Make your variable a global at the top of the stylesheet, and remove the quotes around '$pusuff' when you use it.
RE: difficulty with variable - Added by Anonymous over 15 years ago
Legacy ID: #7508824 Legacy Poster: Michael Kay (mhkay)
A good place to get XSLT coding help is the xsl-list at mulberrytech.com. This forum is intended for problems specific to the Saxon product - it's not a free stylesheet debugging service. The most obvious thing wrong with this like of code: <xsl:when test="./voto_scritto/@punti<'$pusuff'"> is that the variable reference $pusuff is in quotes. The next thing wrong with it is that the variable isn't in scope (it's only in scope within the <table> element).
RE: difficulty with variable - Added by Anonymous over 15 years ago
Legacy ID: #7510807 Legacy Poster: Alessandro Vallin (avalli)
Thanks a lot for all your replies and support. And sorry for posting such a trivial question on this forum. I've just started using XSLT and I was desperate for an answer... All the best, Alessandro
Please register to reply