![]() | |||||||||||||||||||||
![]() |
|
|
I Can See Clearly Now
Data is nice, but making it readable is even nicer. This is where XSL comes in. XSL like we stated before allows us to assign HTML tags so that it can be displayed on a website in a pretty form. XSL allows for a standard template to be created to which the data is later married. XSL contains a few functions for sorting and moving through the data. These functions include:
for-each The following example is the XSL that styles the previous XML data, this file is named example.xsl. If you have Internet Explorer 5.0 and above you can look at the actual XSL file by clicking the link.
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<html>
<body>
<table width="90%" border="0" cellspacing="3">
<xsl:for-each select="tutorial-menu/subject">
<tr><td colspan="3" bgcolor="#336699">
<font color="white" face="arial"><b><i>
<xsl:value-of select="subject-name"/></i></b>
</font></td></tr>
<xsl:for-each select="topic" order-by="+ topic-name">
<tr><td width="2%"></td>
<td colspan="2" bgcolor="#CCCCCC">
<font size="2" face="arial"><b>
<xsl:value-of select="topic-name"/>
</b></font></td></tr>
<xsl:for-each select="tutorial">
<tr><td width="2%"></td><td width="5%">
</td><td>
<font size="2" face="arial"><b>
<A>
<xsl:attribute name="href">
<xsl:value-of select="link"/>
</xsl:attribute>
<xsl:value-of select="title"/>
</A>
</b><i><xsl:value-of select="update-time"/></i>
</font></td></tr>
<tr><td width="2%"></td><td width="5%"></td><td>
<table border="0">
<xsl:for-each select="sections">
<tr><td width="5%"></td><td>
<font size="1" face="arial">
<A>
<xsl:attribute name="href">
<xsl:value-of select="link"/>
</xsl:attribute>
<xsl:value-of select="section"/>
</A>
</font></td></tr>
</xsl:for-each>
</table></td></tr>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Several for-each loops are implemented in the preceding example along with an order filter. This allows all the data contained within the "tutorial-web/subject" elements to be accessed and then within that all the "tutorial" elements and so on. This is an example of looping through elements contained within elements which are also looped.
|
Section 2: XSL Power! Section 3: Same Difference Section 4: XSL+XML+ASP=HTML
| ||||||||||||||||||||||