Developing XSLT-based Applications in ASP.NET 2.0 - Working with all siblings available at a particular path
(Page 5 of 7 )
Let us now consider working with more than one tag at a time (belonging to the same row or siblings). The following code sample achieves the same:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:apply-templates select="SQLData/Rows" />
</xsl:template>
<xsl:template match="SQLData/Rows">
<xsl:value-of select="EmployeeID"/>,
<b>
<xsl:value-of select="FirstName"/>,
</b>
<br />
</xsl:template>
</xsl:stylesheet>
From the above you can understand that I defined a new template for “SQLData/Rows.” Within that template, I am extracting “EmployeeID” and “FirstName” and transforming them according to our needs.
Let us now further extend the above XSLT to have sibling level and tag level templates as shown in the following:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:apply-templates select="SQLData/Rows" />
</xsl:template>
<xsl:template match="SQLData/Rows">
<xsl:value-of select="EmployeeID"/>,
<xsl:apply-templates select="FirstName" />
<br />
</xsl:template>
<xsl:template match="FirstName">
<b>
<xsl:value-of select="."/>,
</b>
</xsl:template>
</xsl:stylesheet>
As you can see, you can define and work with any number of templates at various levels according to your needs.
Next: Transforming XML data to HTML tables using XSLT >>
More ASP.NET Articles
More By Jagadish Chaterjee