Click here to Skip to main content
Licence CPOL
First Posted 17 Apr 2007
Views 15,574
Downloads 66
Bookmarked 18 times

XSL Transformer

By | 17 Apr 2007 | Article
A simple editor for XSL transformations.

Introduction

This editor helps to test the XSL transformations. It is very useful if you are developing XSLT for your web project and want to test before publishing into the web server. You can also check the XSLT syntax errors and the output of the transformation using this editor.

Editor

Background

In my recent assignment, I got a chance to work on XSLT. When I was developing XSLT files, I found MSXML.dll does not support all the functions available in the current XSLT/XPath version. So I made this little tool to test the XSLT output and syntax errors.

Using the Code

Dim sResult As New System.IO.StringWriter

'loan XML
xmlDoc.LoadXml(rtxtXML.Text)

'load XSL
xslDoc.LoadXml(rtxtXSL.Text)
Dim xslTransform As New System.Xml.Xsl.XslTransform

'if xsl has any import statements create Evidence For the Url
Dim evidence As System.Security.Policy.Evidence = _
    XmlSecureResolver.CreateEvidenceForUrl("http://localhost/")

evidence.AddAssembly(Me.GetType().Assembly)
xslTransform.Load(xslDoc, New Xml.XmlUrlResolver, evidence)
xslTransform.Transform(xmlDoc, Nothing, sResult, Nothing)
rtxtResult.Text = sResult.GetStringBuilder().ToString()

'select result tab
tbctlMain.SelectedIndex = 2
Trace("Transformation compleated....")

How to Use

  1. Copy the XML data in the XML tab or open an existing XML file from the File menu.
  2. Sample XML:
    <?xml version='1.0'?>
    <!-- This file represents a fragment of a book store inventory database -->
    <bookstore>
      <book genre="autobiography" publicationdate="1981" ISBN="1-861003-11-0">
        <title>The Autobiography of Benjamin Franklin</title>
        <author>
          <first-name>Benjamin</first-name>
          <last-name>Franklin</last-name>
        </author>
        <price>8.99</price>
      </book>
      <book genre="novel" publicationdate="1967" ISBN="0-201-63361-2">
        <title>The Confidence Man</title>
        <author>
          <first-name>Herman</first-name>
          <last-name>Melville</last-name>
        </author>
        <price>11.99</price>
      </book>
      <book genre="philosophy" publicationdate="1991" ISBN="1-861001-57-6">
        <title>The Gorgias</title>
        <author>
          <name>Plato</name>
        </author>
        <price>9.99</price>
      </book>
    </bookstore>
  3. Copy the XSL script in the XSL tab or open an existing XSL file from the File menu.
  4. Sample XSL:
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:template match="/">
     <root>
      <xsl:apply-templates/>
     </root>
     </xsl:template>
     <xsl:template match="bookstore">
     <!-- Prices and books -->
      <bookstore>
       <xsl:apply-templates select="book"/>
      </bookstore>
     </xsl:template>
     <xsl:template match="book">
      <book>
       <xsl:attribute name="ISBN">
        <xsl:value-of select="@ISBN"/>
       </xsl:attribute>
       <price><xsl:value-of select="price"/></price><xsl:text>
       </xsl:text>
      </book>
     </xsl:template>
    </xsl:stylesheet>
  5. Click on the Transform menu item to test the transformation. If the the XSLT is good, then you should see the output on the Result tab.

History

  • Created on 4/17/2007.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Srinivas-Miriyala

Software Developer (Senior)

United States United States

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralIts very useful PinmemberRamesh.Tsi2:43 10 May '07  
GeneralBelow error generated while executing the code PinmemberKolluru S23:26 7 May '07  
AnswerRe: Below error generated while executing the code PinmemberSrinivas-Miriyala5:27 9 May '07  
GeneralExcellent ! PinmemberZ.J.Liu11:24 21 Apr '07  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 17 Apr 2007
Article Copyright 2007 by Srinivas-Miriyala
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid