Data Transformation using XSLT Stylesheets

Estudies4you
Data Transformation using XSLT Stylesheets

Data Transformation using XSLT Stylesheets

Now, let's actually use an XSLT stylesheet to transform XML data into HTML data. Here, we will take a look at an example that uses an XSLT stylesheet (EX2) to transform an XML Document (EX1) representing user information. EX3 shows the actual data transformed into an HTML format. The second line of EX1 is where the designated XSLT stylesheet (list2.xsl) is applied.

Example 1: Source XML Document ilistl.xml)
<?xml version="1.0" 7>
<?xml-stylesheet type="text/xs1" href="list2.xs1"?>
<UserList>
 <User>
<Name>Naresh Kumar</Name>
<Account>Naresh</Account>
</User>
</UserList>
                             
Example 2: XSLT Stylesheet (Iist2.xsl)
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xs1="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
 <hl>welcome</h1> Mr. <xsl:value-of select="UserList/User/Name" /><br/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Example 3: Transformation Result list3.html
<html>
<body>
<hl>Welcome</hl>
Mr. Kumar<br>
</body>
</html>

Summary
By the end of this module, you have to learnt:
  • DOM (Document Object Model) defines a standard way for accessing and manipulating documents. All elements of an XML can be accessed through the DOM tree
  • XML elements, their text, and their attributes are all known as nodes
  • HTML DOM (HTML Document Object Model), defines a standard way for accessing and manipulating HTML documents. All HTML elements can be accessed through the HTML DOM
  • SAX (Simple API for XML), Is an event-based sequential access parser API developed by the XML-DEV mailing list for XML documents
  • XPath is used to navigate through elements and attributes in an XML document. It is a major element in W3C's XSLT standard. It uses path expressions to navigate in XML documents
  • An XML transformation language is a programming language designed specifically to transform an input XML document into an output XML document. There are two cases of transformation i.e., XML to XML and XML to Data
  • XSLT is the best known XML transformation language. It has become a new W3C recommendation since January 2007

To Top