Home » XML Basics » 11 - XSL
11

Making XSL File

In the previous chapters, you learned about HTML. You can use that knowledge and apply it in this chapter so that you would know hot to make a stylesheet by making an XSL file.

Using your HTML knowledge from the earlier chapters, you can make a stylesheet like the one below.

 <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">  <xsl:template match="classcard">   <html>   <body>     <h2>Classcards</h2>     <table border="1">     <tr>       <td>Name</td>       <td>Grade</td>     </tr>     <xsl:for-each select="card">     <tr>       <td><xsl:value-of select="name"/></td>       <td><xsl:value-of select="result"/></td>     </tr>     </xsl:for-each>     </table>   </body>   </html>  </xsl:template> </xsl:stylesheet>  

Save it in *.XSL format. It should look something like this on your desktop .

Simply insert the reference to the stylesheet in an XML file like how it was done below.

 <?xml version = "1.0"?>   <?xml-stylesheet type="text/xsl" href="ccformat.xsl"?>  <classcard dategiven = "9/27/05" xmlns:xlink = "http://www.w3.org/1999/xlink" >  <card>  <name> Sara </name> <subject> programming </subject> <result> <grade> 3.5/4.0 </grade> very industrious and recites a lot </result> <complaints xlink:href = "http://www.mcdonalds.com"> Eats McDonald’s in the middle of class </complaints>  </card>  <card>  <name> Michael </name> <subject> programming </subject> <result> <grade> 3.0/4.0 </grade> does well on written exams but does not recite </result> <complaints> </complaints>  </card>  </classcard>  

Open your browser and the resulting XML file should look like the image below.

Classcards