XSLT Transformation, XSLT Tutorial, Global Guideline

Bookmark Bookmark: XSLT Transformation, XSLT Tutorial
Forum | Blog


      Home                    

Basic XSLT Tutorial.     
 XSLT Introduction.          
 XSLT Templates.            
 XSLT Attributes.              
 XSLT Transformation.
 XSLT Variables.              
 XSLT Formatting.            
 XSLT Loops.                   
 XSLT Sorting.                 
 XSLT Conditions.             
 XSLT Multi Selection.     
 XSLT Functions.              
 XSLT Copying.                
 XSLT Combining.           
 XSLT Summary.              

XSLT Tutorial >> XSLT Transformation.


     Back             Next     



XSL transformation, an XSLT processor reads both an XML document and an XSLT style sheet. Based on the instructions the processor finds in the Extensible Stylesheet Language, it outputs a new XML document or fragment thereof. There is also special support for outputting some HTML. With some effort most XSLT processors can also be made to output for all intents and purposes logical text, though XSLT is designed primarily for transformation of XML to XML and XML to HTML documents.

Kinds of XML Nodes

For the purposes of XSLT, elements, attributes, namespaces, processing instructions, and comments are counted as nodes. Furthermore, the root of the XML document must be distinguished from the root element. Thus, Extensible Stylesheet Language processors model an XML file as a tree that contains seven kinds of nodes.

  • The root element of XML
  • Elements in root
  • Text in elements
  • Attributes of elements
  • Namespaces of any element
  • Processing instructions are functions to transform such as loops variables etc.
  • Comments in line or multiple lines.

XSLT and XPath

XSLT relies upon the W3C's XPath language for identifying subsets of the source documents tree, as well as for performing required calculations. XPath also provides a range of built-in functions, which XSLT itself further augments. This reliance upon XPath adds a great deal of power and flexibility to XSLT for navigation.

XSLT 2.0 relies on XPath version 2.0. both specifications were published on the same date. Similarly, Extensible Stylesheet Language version 1.0 works with XPath version 1.0.

Examples of XSLT Transformation in HTML and XML

XML Code for XSLT Transformation Example

<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="xslt_Transformation.xsl"?>
<employees>
  <employee username="Emp1">
   <employee_id>104</employee_id>
   <employee_name>Smith</employee_name>
  </employee>
  <employee username="Emp2">
   <employee_id>107</employee_id>
   <employee_name>Mariya</employee_name>
  </employee>
</employees>

Example of XML to XML Transformation [xslt_Transformation.xsl]

<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="https://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/> 
 <xsl:template match="/">
  <root> <xsl:apply-templates/> </root>
 </xsl:template>

 <xsl:template match="//employee">
  <name username="{@username}">
   <xsl:value-of select="employee_name" />
  </name>
 </xsl:template>

</xsl:stylesheet>

Example of XML to HTML Transformation [xslt_Transformation1.xsl]

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="https://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:template match="/employees">
<html xmlns="https://www.w3.org/1999/xhtml">
  <head> <title>XSLT Transformation Example into HTML</title> </head>
<body>
  <h1>
    <a href="https://www.globalguideline.com/xslt"><font color="0066CC">
      Example of XSLT Transformation at Global Guide Line XSLT Tutorial
    </font></a>
  </h1>
  <h2>Employees at Global Guide Line</h2>
  <ul> 
    <xsl:apply-templates select="employee">
      <xsl:sort select="employee_name" />
    </xsl:apply-templates>
  </ul>
</body>
</html> 
</xsl:template>

<xsl:template match="employee">
  <li>
    <xsl:value-of select="employee_id"/>, 
    <xsl:value-of select="employee_name"/> 
  </li> 
</xsl:template>

</xsl:stylesheet>

Sources of XSLT Transformation in HTML and XML Examples


Viewing XML Files in Firefox and Internet Explorer Browsers.

Open the XML file simply by double click - Then the XML document will be displayed with color-coded root and child elements. Plus (+) or Minus mark (-) to the left of the all elements can be clicked to expand or collapse the element structure. To view the raw XML source of any XML document without the + and - signs, select "View Page Source" or "View Source" from the browser menu of you opened browser.

Viewing XML Files in Netscape Navigator.

Open the XML file in Netscape Navigator, then right-click in XML document and select "View Page Source". The XML file will then be displayed with color-coded root and child elements.

Viewing Files of XML in Opera 7.

Open the XML file in Opera browser, then right-click in XML document and select "Frame" / "View Source". The XML document will be displayed as plain text file with XML coiding..

     Back             Next     


 

[ About ] [ Contact ] [ Home ]
[ Links ] [ Site Map ] [ Services ] [ Privacy ]

Copyright 2005 -  2018 www.globalguideline.com All rights reserved. (Best viewed in IE 6.0+ or Firefox 2.0+ at 1024 * 768 or higher) 228 visitors are online now