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

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
TABLE OF CONTENTS:
  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
SEARCH DEVARTICLES

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.


blog comments powered by Disqus
XML ARTICLES

- 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 
Support 

Developer Shed Affiliates

 




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