File: Data.xml
<?xml version="1.0"?>
<results group="A">
<match>
<date>10-Jun-98</date>
<team score="2">team 1</team>
<team score="1">team 2</team>
</match>
<match>
<date>10-Jun-98</date>
<team score="2">team 3</team>
<team score="2">team 4</team>
</match>
</results>
File: Transform.xslt
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="table-heading">
<tr>
<td>
<b>Date</b>
</td>
<td>
<b>Home Team</b>
</td>
<td>
<b>Away Team</b>
</td>
<td>
<b>Result</b>
</td>
</tr>
</xsl:variable>
<xsl:template match="/">
<html>
<body>
<h1>
Matches in Group
<xsl:value-of select="/*/@group" />
</h1>
<xsl:for-each select="//match">
<h2>
<xsl:value-of
select="concat(team[1], ' versus ', team[2])" />
</h2>
<table bgcolor="#cccccc" border="1"
cellpadding="5">
<xsl:copy-of select="$table-heading" />
<tr>
<td>
<xsl:value-of select="date" />
 
</td>
<td>
<xsl:value-of select="team[1]" />
 
</td>
<td>
<xsl:value-of select="team[2]" />
 
</td>
<td>
<xsl:value-of
select="concat(team[1]/@score, '-', team[2]/@score)" />
 
</td>
</tr>
</table>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Output:
<html>
<body>
<h1>
Matches in Group
A
</h1>
<h2>team 1 versus team 2</h2>
<table bgcolor="#cccccc" border="1" cellpadding="5">
<tr>
<td><b>Date</b></td>
<td><b>Home Team</b></td>
<td><b>Away Team</b></td>
<td><b>Result</b></td>
</tr>
<tr>
<td>10-Jun-98
</td>
<td>team 1
</td>
<td>team 2
</td>
<td>2-1
</td>
</tr>
</table>
<h2>team 3 versus team 4</h2>
<table bgcolor="#cccccc" border="1" cellpadding="5">
<tr>
<td><b>Date</b></td>
<td><b>Home Team</b></td>
<td><b>Away Team</b></td>
<td><b>Result</b></td>
</tr>
<tr>
<td>10-Jun-98
</td>
<td>team 3
</td>
<td>team 4
</td>
<td>2-2
</td>
</tr>
</table>
</body>
</html>
|