Simple XSLT Example Introduction In this article i am explaining what is XSLT and how to use it to transform a xml document using a simple example. What is XSLT XSLT stands for EXtensible Stylesheet Language Transformations. XSLT transforms an XML document into another XML document, or another type of document that is recognized by a browser, like HTML. With XSLT you can add/remove elements and attributes to or from the output file. You can also rearrange and sort elements, perform tests and make decisions about which elements to hide and display, and a lot more. Using Code Using code you can easily transform a xml document into other xml document with style like following figure: The code of xslt file is as follow:
Explaination of Code First tag define that it is an xml file because xslt is also an xml file Then second tag declares the document to be an XSL style sheet is To get access to the XSLT elements, attributes and features we must declare the XSLT namespace at the top of the document. The xmlns:xsl="http://www.w3.org/1999/XSL/Transform" points to the official W3C XSLT namespace. If you use this namespace, you must also include the attribute version="1.0". Element The element is used to build templates. The match attribute is used to associate a template with an XML element. The match attribute can also be used to define a template for the entire XML document. The value of the match attribute is an XPath expression (i.e. match="/" defines the whole document). The content inside the element defines some HTML to write to the output.
The element can be used to extract the value of an XML element and add it to the output stream of the transformation like
Element The XSL element can be used to select every XML element of a specified node-set