XSLT (Extensible StyleSheet Language Transformations)

Lakhangarg
Posted by in Others category on for Beginner level | Views : 4993 red flag

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.
Introduction
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


Page copy protected against web site content infringement by Copyscape

About the Author

Lakhangarg
Full Name: Lakhan Pal
Member Level: Silver
Member Status: Member,Moderator
Member Since: 8/17/2009 12:39:46 AM
Country: India

http://lakhangarg.blogspot.com
Hello Friends Myself Lakhan Pal Garg and i am a B.Tech (IT) Graduate and having 8+Years of Exp. in Microsoft Technology. I have Write a Blog Named Free Code Snippets (http://lakhangarg.blogspot.com/) I hope you must visit my blog as your valuable feedback will motivate me to write more and improve my mistake. If you want to gain more knowledge then share it with others.

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)