Overview of XSLT
XSLT stands for EXtensible Stylesheet Language Transformations.
1. XSLT stands for XSL Transformations
2. XSLT transforms an XML document into another XML document
3. XSLT uses XPath to navigate in XML documents
4. XSLT is a W3C Recommendation
As we know XML is light weight and we can also store sensitive data in that. XSLT
is very useful for wireless applications. Using XSLT we can create html pages by
traversing a XML document
Below example illustrates how to transform a xml document to html.
XML file
<?xml version="1.0" encoding="ISO-8859-1"?>
<Employees>
<Employee>
<name>xxx</name>
<dept>abc</dept>
<country>USA</country>
<salary>2000</salary>
</Employee>
<Employee>
<name>xyz</name>
<dept>dddd</dept>
<country>USA</country>
<salary>2000</salary>
</Employee>
<Employee>
<name>Abc</name>
<dept>dsds</dept>
<country>USA</country>
<salary>3000</salary>
</Employee>
<Employee>
<name>ccc</name>
<dept>HR</dept>
<country>USA</country>
<salary>54545</salary>
</Employee>
<Employee>
<name>aaa</name>
<dept>Admin</dept>
<country>USA</country>
<salary>54454545</salary>
</Employee>
</Employees>
|
XSLT file
<?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>
<h2>XYZ Company</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Name</th>
<th>Dept</th>
<th>Country</th>
<th>Salary</th>
</tr>
<xsl:for-each select="Employees/Employee">
<tr>
<td><xsl:value-of select="name" /></td>
<td><xsl:value-of select="dept" /></td>
<td><xsl:value-of select="country" /></td>
<td><xsl:value-of select="salary" /></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
|
Output
XYZ Company
| Name | Dept | Country | Salary |
|---|
| xxx | abc | USA | 2000 |
| xyz | dddd | USA | 2000 |
| Abc | dsds | USA | 3000 |
| ccc | HR | USA | 54545 |
| aaa | Admin | USA | 54454545 |
Conclusion
XSLT is used to transform an XML document into below format
XML document
HTML
XHTML
Normally XSLT does this by transforming each XML element into an XHTML element.
Biswa Pujarini MohapatraPosted Jan 29, 2014, 10:18 PM
yes it is possible check this http://support.microsoft.com/kb/264665
MacPosted Jan 22, 2014, 9:03 AM
Is it Possible to generate the xslt from the HTML? Please reply..
mathes sPosted Oct 18, 2011, 1:47 AM
Hi, above is fine code.. really usefull for beginners.. but i need the following , 1) How to store an aspx page or xhtml page into xml with xsl?.. 2) How to load html controls and tags from xml ,xsl file which must have all the properties and events for the html controls? 3) How to write events for the dynamically generated controls from xml?
Biswa Pujarini MohapatraPosted Aug 29, 2011, 2:25 AM
Hi Avadesh, Thanks for your comment. In this case you can write XSLTs and XSLTtransform to convert into HTML
avadesh chauhanPosted Aug 28, 2011, 10:36 PM
Hi Biswa, Is there any way to convert XML directly into HTML?? As i am working on a project in which i m getting dynamic XMLs to convert & save into HTML format. plz revert asap. Thanks, Avi