XML on the network can often see the background color by row alternately set table, more beautiful. But not necessarily what advanced Server technology, with simple xsl+xml still can be very good to achieve them.
For example, we have an XML document that records the URL:
<?xml version= "1.0" encoding= "Utf-8"?>
<?xml-stylesheet type= "text/xsl" href= "xsltfilellink.xsl"?>
<items>
<roomitem>
<text> Sina </text>
<link>http://www.sina.com.cn</link>
</roomitem>
<roomitem>
<text>yahoo</text>
<link>http://www.yahoo.com</link>
</roomitem>
<roomitem>
<text>google</text>
<link>http://www.google.com</link>
</roomitem>
<studyitem>
<text>html Easy Tutorials </text>
<link><a href= "gohttp://www.shanxiwindow.net/teaching/htmlbook/" >go</a></link>
</studyitem>
<studyitem>
<text>javascript Chinese profile </text>
<link>http://www.lib.tsinghua.edu.cn/chinese/INTERNET/JavaScript/</link>
</studyitem>
<studyitem>
<TEXT>MSDN Chinese site </text>
<link>http://www.microsoft.com/china/msdn/default.mspx</link>
</studyitem>
<studyitem>
<text>microsoft. Net Framework SDK QuickStart Tutorials </text>
<link>http://chs.gotdotnet.com/quickstart/default.aspx</link>
</studyitem>
</items>
Now, I would like to classify him as a table with two colors alternating in rows. As shown in the following illustration:
XSL can write this,
<?xml version= "1.0" encoding= "Utf-8"?>
<xsl:stylesheet version= "1.0"
Xmlns:xsl= "Http://www.w3.org/1999/XSL/Transform" >
<xsl:template match= "/" >
<body>
<!--
This is a XSLT template file. Fill in the, with the
XSL elements which would transform your XML to XHTML.
-->
<H1>XSLT Application Test
<table width= "100%" border= "1" >
<tr bgcolor= "#C9BBAD" >
<th>name</th>
<th>link</th>
</tr>
<xsl:for-each select= "Items/roomitem" >
<xsl:choose>
<xsl:when test= "(Position () mod 2) = 0" >
<tr bgcolor= "#C9BBAD" >
<td>
<xsl:value-of select= "Text"/>
</td>
<td>
<xsl:value-of select= "link"/>
</td>
</tr>
</xsl:when>
<xsl:otherwise>
<tr>
<td>
<xsl:value-of select= "Text"/>
</td>
<td>
<xsl:value-of select= "link"/>
</td>
</tr>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</table>
<br/>
<table width= "100%" border= "1" >
<tr bgcolor= "#C9BBAD" >
<th>name</th>
<th>link</th>
</tr>
<xsl:for-each select= "Items/studyitem" >
<xsl:choose>
<xsl:when test= "(Position () mod 2) = 0" >
<tr bgcolor= "#C9BBAD" >
<td>
<xsl:value-of select= "Text"/>
</td>
<td>
<xsl:value-of select= "link"/>
</td>
</tr>
</xsl:when>
<xsl:otherwise>
<tr>
<td>
<xsl:value-of select= "Text"/>
</td>
<td>
<xsl:value-of select= "link"/>
</td>
</tr>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</table>
</body>
</xsl:template>
</xsl:stylesheet>