<?xml version = "1.0"?>

<!-- Fig. 20.24 : games.xsl        -->
<!-- A simple XSLT transformation  -->

<!-- reference XSL stylesheet URI   -->
<xsl:stylesheet version = "1.0" 
   xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">

   <xsl:output method = "html" omit-xml-declaration = "no" 
      doctype-system = 
         "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd" 
      doctype-public = "-//W3C//DTD XHTML 1.0 Strict//EN"/>

<!-- ricerca l'elemento root; template  applicato all'intero documento XML -->
<xsl:template match = "/"> 

  <html xmlns="http://www.w3.org/1999/xhtml">

    <head>
       <title>Sports</title>
    </head>

    <body>
		  <xsl:choose>
				<xsl:when test="count(sports/game)=0">
				 <p>Non &#0232; presente alcun elemento</p>
				</xsl:when>
				<xsl:when test="count(sports/game)>0">

        <!-- inserisce ogni valore degli elementi nome e descrizione  -->
        <!-- nelle righe di una tabella.                              -->

 				 <table border = "1" bgcolor = "cyan" summary="esempio di uso di XML ed XSL">
          <thead>

          <tr>
           <th>ID</th>
           <th>Sport</th>
           <th>Information</th>
         </tr>

         </thead>
					  <xsl:for-each select = "sports/game">
						<!-- ordinamento in ordine ascendente rispetto ai valori di 'id' -->
						<xsl:sort select = "@id" data-type = "number" 
                    order = "ascending"/>
           <tr>
					  <!-- per accedere ai valori degli attributi di un elemento XML il nome 
						di questi stessi deve essere precedtuo da '@' -->
             <td><xsl:value-of select = "@id"/></td>
             <td><xsl:value-of select = "name"/></td>
             <td><xsl:value-of select = "paragraph"/></td>
           </tr>

          </xsl:for-each>
				</table>		

				</xsl:when>
				</xsl:choose>
     </body>

  </html>

</xsl:template>

</xsl:stylesheet>