XML
  Home arrow XML arrow Page 2 - Understanding XSLT transformations: Your O...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
XML

Understanding XSLT transformations: Your Own `XML Transformation Utility`
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 5
    2005-12-28

    Table of Contents:
  • Understanding XSLT transformations: Your Own `XML Transformation Utility`
  • Understanding the XML and XSLT
  • “XML transformation utility,” is it really necessary?
  • Developing your own XML transformation utility
  • Understanding the XML transformation utility
  • Testing further with different types of XML

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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"?>
    <greeting>
                Hello, World!
    </greeting>

    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"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    ………
    </xsl:stylesheet>

    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="/">
    ………
    </xsl:template>

    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:

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

    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.

    More XML Articles
    More By Jagadish Chaterjee


       · Hello guys..you can try my simple "XML Transformation Utility" here and give me some...
     

    XML ARTICLES

    - 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
    - Simple Web Syndication with RSS 2.0
    - Java UI Design with an IDE
    - UI Design with Java and XML Toolkits
    - Displaying ADO Retrieved Data with XML Islan...
    - Widget Walkthrough
    - Introduction to Widgets
    - The Why and How of XML Data Islands






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT