Developing XSLT-based Applications in ASP.NET 2.0 - Testing XSLT using ASP.NET 2.0
(Page 2 of 7 )
When the button is clicked (as given in previous section), it generates an XML document (from the database), which is similar to the following hierarchy:
<SQLData>
<Rows>
<EmployeeID>1</EmployeeID>
<FirstName>Guy</FirstName>
<JobTitle>Production Technician - WC60</JobTitle>
</Rows>
<Rows>
<EmployeeID>2</EmployeeID>
<FirstName>Kevin</FirstName>
<JobTitle>Marketing Assistant</JobTitle>
</Rows>
.
.
.
</SQLData>
The following is the first sample XSLT to test:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<b>
<xsl:value-of select="SQLData/Rows/FirstName"/>
</b>
</xsl:template>
</xsl:stylesheet>
When the XML document gets transformed based on the above XSLT, it displays the “FirstName” of the first employee in bold. The result of the above transformation would be similar to the following:
<b>
Guy
</b>
The first and the most important construct is the following:
<xsl:template match="/">
.
.
</xsl:template>
Any construct starting with “xsl:template” is called a “template.” The template is a blueprint for transformation. In the above case, it checks whether the current “context” is at “root” or not. If the “context” is at root, the template available within the construct is applied.
The following is the body of above template:
<b>
<xsl:value-of select="SQLData/Rows/FirstName"/>
</b>
The above transforms the first value (or text) available in “SQLData/Rows/FirstName” to display as bold.
Next: Separating templates from the root template >>
More ASP.NET Articles
More By Jagadish Chaterjee