Bende gördüğüm güzel örnekleri parça parça burada toplayacağım.
XML verisi aşağıdaki gibi olsun demiş BSY:
<?xml version="1.0" encoding="utf-8" ?>
<Muzikler>
<Muzik ID="1">
<Soyleyen>Coldplay</Soyleyen>
<AlbumAdi>X and Y</AlbumAdi>
<CikisTarihi>2005</CikisTarihi>
<Fiyat>28</Fiyat>
<Tip>CD</Tip>
</Muzik>
<Muzik ID="2">
<Soyleyen>Depeche Mode</Soyleyen>
<AlbumAdi>Playing The Angel</AlbumAdi>
<CikisTarihi>2005</CikisTarihi>
<Fiyat>25</Fiyat>
<Tip>CD</Tip>
</Muzik>
.
.
.
<Muzikler>
TEMPLATE
<xsl:template match="/">
FOR-EACH & VALUE-OF
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1>Müzik Dükkanım</h1>
<table border="1" borderColor="Black" cellpadding="0" cellspacing="0">
<tr bgcolor="#FFCC66">
<th>ID</th>
<th>Söyleyen</th>
<th>Albüm Adı</th>
<th>Çıkış Tarihi</th>
<th>Satış Fiyatı</th>
<th>Cd/Dvd/Kaset</th>
</tr>
<xsl:for-each select="Muzikler/Muzik">
<tr>
<td>
<xsl:value-of select="@ID"/>
</td>
<td>
<font size="2" color="Blue">
<xsl:value-of select="Soyleyen"/>
</font>
</td>
<td>
<b>
<xsl:value-of select="AlbumAdi"/>
</b>
</td>
<td align="right">
<xsl:value-of select="CikisTarihi"/>
</td>
<td>
<b>
<xsl:value-of select="Fiyat * 1.5"/> Ytl
</b>
</td>
<td>
<xsl:value-of select="Tip"/>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
SORT
<xsl:for-each select="Muzikler/Muzik">
<xsl:sort select="AlbumAdi" order="descending" data-type="text"/>
<xsl:for-each select="Muzikler/Muzik">
<xsl:sort select="AlbumAdi" order="descending" data-type="text"/>
<xsl:if test="Tip=’DVD’">
<tr>
<td><xsl:value-of select="@ID"/></td>
<td><font size="2" color="Blue"><xsl:value-of select="Soyleyen"/></font></td>
<td><b><xsl:value-of select="AlbumAdi"/></b></td>
<td align="right"><xsl:value-of select="CikisTarihi"/></td>
<td><b><xsl:value-of select="Fiyat * 1.5"/> Ytl</b></td>
<td><xsl:value-of select="Tip"/></td>
</tr>
</xsl:if>
</xsl:for-each>
IF & CHOOSE & WHEN & OTHERWISE
<xsl:if test="Tip=’DVD’ or Tip=’CD’ ">
<xsl:for-each select="Muzikler/Muzik">
<xsl:sort select="AlbumAdi" order="descending" data-type="text"/>
<xsl:if test="Tip=’DVD’ or Tip=’CD’ ">
<tr>
<td><xsl:value-of select="@ID"/></td>
<td><font size="2" color="Blue"><xsl:value-of select="Soyleyen"/></font></td>
<td><b><xsl:value-of select="AlbumAdi"/></b></td>
<td align="right"><xsl:value-of select="CikisTarihi"/></td>
<xsl:choose>
<xsl:when test="Fiyat >35 and Fiyat <55">
<td bgColor="Blue"><font color="White" size="3"><b><xsl:value-of select="Fiyat"/> ytl</b></font></td>
</xsl:when>
<xsl:when test="Fiyat <35">
<td bgColor="Green"><font color="White" size="3"><b><xsl:value-of select="Fiyat"/> ytl</b></font></td>
</xsl:when>
<xsl:otherwise>
<td bgColor="Red"><font color="White" size="3"><b><xsl:value-of select="Fiyat"/> ytl</b></font></td>
</xsl:otherwise>
</xsl:choose>
<td><xsl:value-of select="Tip"/></td>
</tr>
</xsl:if>
</xsl:for-each>
Sunucu tarafından XSL Transformation:
XslCompiledTransform xsltran = new XslCompiledTransform();
xsltran.Load(Server.MapPath("XsltForHtml.xsl"));
xsltran.Transform(Server.MapPath("MuzikDukkanim.xml"), null, Response.Output);
XslCompiledTransform xsltran = new XslCompiledTransform();
XPathDocument doc = new XPathDocument(Server.MapPath("MuzikDukkanim.xml"));
XPathDocument xslDoc = new XPathDocument(Server.MapPath("XsltForHtml.xsl"));
xsltran.Load(xslDoc);
xsltran.Transform(doc, null, Response.Output);