Implement XSL Transformation on XML Document

Lakhangarg
Posted by Lakhangarg under Others category on | Views : 2014
******************************************************************************
XSLT (Extensible StyleSheet Language Transformations)
******************************************************************************
XSL stands for Extensible StyleSheet Language, and is a style sheet language for XML documents. XSLT stands for XSL Transformations. XSL = Style Sheets for XML.XSL consists of three parts:

* XSLT - a language for transforming XML documents
* XPath - a language for navigating in XML documents
* XSL-FO - a language for formatting XML documents

XSLT is a language for transforming XML documents into XHTML documents or to other XML documents. XPath is a language for navigating in XML documents.

Example:
Implement Style on xml data:

*********************** Sample: Sample1.xml ************************
<?xml version="1.0" encoding="ISO-8859-1" ?>
<?xml-stylesheet type="text/xsl" href="Sample1.xslt"?>
<SqlData>
<Table>
<UserName>lakhangarg@gmail.com</UserName>
<FirstName>Lakhan Pal Garg</FirstName>
<Blog>http://www.lakhangarg.blogspot.com</Blog>
</Table>
</SqlData>
******************************************************************************
********************* XSLT Sample: Sample1.xslt ************************
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<b>Author: </b><xsl:value-of select="SqlData/Table/FirstName" /><br/>
<b>Email ID:</b><xsl:value-of select="SqlData/Table/UserName" /><br/>
<b>Blog:</b><xsl:value-of select="SqlData/Table/Blog" />
</body>
</html>
</xsl:template>
</xsl:stylesheet>

******************************************************************************

Code to implement stylesheet on xml document:

XmlDocument docXML = new XmlDocument();
XslTransform docXSL = new XslTransform();
docXML.Load(Server.MapPath("sample1.xml"));
docXSL.Load(Server.MapPath("sample1.xslt"));
Xml1.Document = docXML;
Xml1.Transform = docXSL;


Output:
Author: Lakhan Pal Garg
Email ID:lakhangarg@gmail.com
Blog:http://www.lakhangarg.blogspot.com

Comments or Responses

Login to post response