Home arrow XML arrow Page 2 - Understanding XSLT transformations: Your Own `XML Transformation Utility`

Understanding XSLT transformations: Your Own `XML Transformation Utility`

This article mainly concentrates on the basics of transforming XML documents, along with developing your own utility to transform XML to XSLT using Visual Studio 2005.

Author Info:
By: Jagadish Chaterjee
Rating: 5 stars5 stars5 stars5 stars5 stars / 7
December 28, 2005
  1. · Understanding XSLT transformations: Your Own `XML Transformation Utility`
  2. · Understanding the XML and XSLT
  3. · “XML transformation utility,” is it really necessary?
  4. · Developing your own XML transformation utility
  5. · Understanding the XML transformation utility
  6. · Testing further with different types of XML

print this article

Understanding XSLT transformations: Your Own `XML Transformation Utility` - Understanding the XML and XSLT
(Page 2 of 6 )

With in the previous section, I defined “sample1.xml” as following:

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="Sample1.xsl"?>
            Hello, World!

The first line is just a processing instruction to an XML parser (in simple terms a “parser” is similar to an “interpreter” in old technical terms) that the content of the file is based on XML standards of version “1.0” and so on.

The second line informs the XML parser that the XML document needs to link (or transform) with “Sample1.xsl” at run time.  All the lines after the second line are actually the customized and user-defined structure of the XML data (or information).

Coming to “sample1.xsl”, I shall explain part by part.  Let us consider the following first:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"

I think you are already clear about the first line.  Coming to the next structure (xsl:stylesheet), our entire transformation (“format” for “presenting” xml) lies in between the opening and closing tags of “xsl:stylesheet”.

The next interesting statement would be the following:


<xsl:output method="html"/>

I am just informing to the XSLT transformer that the format should confirm to the rules and regulations of “html”.  Other values would be “text” or “xml”.  Further proceeding we have the following:

<xsl:template match="/">

This is the heart of our transformation.  The parser tries to emit the content (or format) existing within those two tags when it is working on the “root” node of the XML document.  The “root node” is different from the “root element”.  This is the cause of much confusion among several programmers.  The “root element” of the above XML document is “greeting”.  But, the “root node” for any XML document (in general) would always be “/”.  The “Node” refers only to the path but “element” refers only to element(s) present within the XML document.

From the above, when a root node is found by the parser, it transforms XML to the content defined with the matching based on “match="/"”.  The transformation content (or template) is defined as follows:

                              <xsl:value-of select="."/>

So, our transformation starts with HTML, BODY and B tags first.  The following line returns all of the text of “nodes related to current context (which is root node) and all sub nodes of current context”.  In this case, our XML document simply has only one “greeting” element at the root node.  And thus it returns “Hello world” in between bold tags surrounded by BODY and HTML tags.

blog comments powered by Disqus

- Open XML Finally Supported by MS Office
- XML Features Added to Two Systems
- Using Regions with XSL Formatting Objects
- Using XSL Formatting Objects
- More Schematron Features
- Schematron Patterns and Validation
- Using Schematron
- Datatypes and More in RELAX NG
- Providing Options in RELAX NG
- An Introduction to RELAX NG
- Path, Predicates, and XQuery
- Using Predicates with XQuery
- Navigating Input Documents Using Paths
- XML Basics
- Introduction to XPath

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials