XML
  Home arrow XML arrow Page 5 - 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 
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 transformation utility


    (Page 5 of 6 )

    Let me explain the above code part by part:

            ' Load the style sheet.
            Dim xslt As New XslCompiledTransform()
            xslt.Load(Me.txtXSLFilePath.Text)

    The above statement creates an “XslCompiledTransform” object called “xslt”.  It has a method “Load” which can load an existing XSL file.  The second statement (in the above code) does the same.  Further proceeding, we have the following:

            ' Create the writer.
            Dim settings As New Xml.XmlWriterSettings()
            settings.Indent = True
            settings.IndentChars = vbTab

    As we are transforming an XML document to HTML (which again looks very similar to XML syntax and structure), I would like to have the output shown along with proper “indentation”.  To transform with proper “indentation” we need to specify some “settings” using the class “XmlWriterSettings”.

    And thus I created an object (“settings’) based on the class “XmlWriterSettings” and finally specified the proper indentation settings.  Further proceeding we have:

            Dim sw As New IO.StringWriter
            Dim writer As XmlWriter = XmlWriter.Create(sw, settings)

    The transformation is something like a process of rewriting.  And thus, I need to work with a “writer” type of class.  “XmlWriter” is already an existing class, which is purely for this scenario.  For my flexibility, I created an object “writer” by executing the method “XmlWriter.Create” along with an object related to “StringWriter” and our “indentation” settings.  Further proceeding we have the following:

            ' Execute the transformation.
            xslt.Transform(Me.txtXMLFilePath.Text, writer)
            writer.Close()
            Me.txtTransformResult.Text = sw.ToString
            sw.Close()

    The entire process takes place with only the first statement (in the above code fragment).  After successfully transforming the XML file, we close and release resources and finally display the result back to a multi-lined textbox.

    More XML Articles
    More By Jagadish Chaterjee


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

    XML ARTICLES

    - 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
    - Simple Web Syndication with RSS 2.0
    - Java UI Design with an IDE







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek