1 janvier 2007
1
01
/01
/janvier
/2007
12:40
XML - XSLT
Exemple simple et parlant
Soit le fichier XML
<?xmlversion="1.0"encoding="utf-8" ?> <REGIONS> <REGION> <code_departement>03</code_departement> <nom_departement>Allier</nom_departement> </REGION> <REGION> <code_departement>06</code_departement> <nom_departement>Alpes Maritmes</nom_departement> </REGION> <REGION> <code_departement>21</code_departement> <nom_departement>Côte d'or</nom_departement> </REGION> <REGION> <code_departement>34</code_departement> <nom_departement>Hérault</nom_departement> </REGION> . . . </REGIONS> |
Et le fichier XSL
<?xmlversion="1.0"encoding="iso-8859-1"?> <xsl:stylesheetversion="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <!-- 1 --> <xsl:templatematch="/"> <html> <bodystyle="background-color:#FFFFFF; color:#000000; font-size:9px; font-weight:bold"> <divstyle="background-repeat:repeat-x; padding:2 px; margin:0 px; height: 79px; border: solid 1px white;"> <h2>Rapport [Entreprises]</h2> <br /> <table> <tr> <td>Code département</td> <td>Nom</td> </tr> </table> <!-- 2 --> <xsl:apply-templates/> </div> </body> </html> </xsl:template> <!-- 3 match = « expression xpath »--> <xsl:templatematch="REGIONS/REGION"> <table> <tralign="center" style="background-color:#BC8F8F;"> <tdstyle="color:white; background-color:#cc0000;font-weight:bold"> <!-- select= "expression xpath" pour sélectionner élément du fichier xml à insérer--> <xsl:value-ofselect="code_departement"/> </td> <tdstyle="color:white; background-color:#cc0000;font-weight:bold"> <xsl:value-ofselect="nom_departement"/> </td> </tr> </table> </xsl:template> </xsl:stylesheet> |
un excellent site sur tout ce qui touche à XML ou au web
http://www.laltruiste.com/document.php?url=http://www.laltruiste.com/coursxsl/sommaire.html