XSLT Transformations and XSLT Intellesense within the .NET IDE

With xml and xslt transformations becoming a large part of many business applications it would be beneficial to have this functionality in the .NET IDE.  Following are the instructions for adding xslt transformations  and intellesense to xslt documents to the .NET IDE.

This additional functionality is achieved by implementing a macro written in VB.NET and a schema that depicts the hierachical relationship of the xslt syntax.  The first section gives instructions on how to load the macro into a demo project and transform some sample xslt against a sample xml file.  The second section gives detailed instructions on what to do with the included xsd file to get intellesense when working with xslt documents.  

About the zip file:

The zip file included with this article contains a series of files that give the IDE its new functionality.  The xsltfunctions.vsmacro  file is the macro we will discuss first and the rest of the files are for the second part of the article. 

Part 1 Loading and Using the Macro 

1. Creating a demo project.

XsltTr1.jpg 

Open the .NET IDE and select a console application with the name of MyXsltSample.

For simplicity we will use a console application to demonstrate this new functionality, however you could use any type of project you desire.

XsltTr2.jpg

2. Navigate to the ToolsMacrosLoad Macro Project menu item as shown above and open the macro project included in the zip file called XsltFunctions.  

XsltTr3.jpg

3. You should now see a macro project in your macro explorer named XsltFunctions as shown above with a child node named xsltTransform.  The macro is now ready to run by double clicking the xsltTransform node, however we must add an xslt file to the project so we have something to transform.

XsltTr4.jpg

4. Navigate to the .NET solution explorer and right click on the project to get the menu shown above and select Add Existing Item.  Next select the xslt file included in the zip file named sampleXslt.xslt this will add the file to the current project. 

XsltTr5.jpg 

5. Finally, navigate to the Macro Explorer again (as shown above) and double click on the XslTransform node this will bring up a file dialog box.  You need to select an xml source document for the transformation, for this demo navigate to the included file named sample.xml and click open.  If all went well you should now see a new window in the IDE with the newly transformed xml document. 

Part 2 Adding xslt Intellesense to the .NET IDE. 

Now that we know we can transform xslt documents inside the .NET IDE it would be nice to get intellesense when working with xslt documents. 

The schema required to achieve this functionality was originally developed by the people at http://www.fesersoft.com/dotNet/ and more information can be found there in regards to this functionality. 

The zip file is outlined at the top of this article please refer to that section for a description of which files relate to part one of the article and which files relate to part two.  The following steps outlined come directly from the ReadMe.txt file in this directory. 

  1. Locate your Microsoft Visual Studio.Net installation folder. (The default location is Program Files\Microsoft Visual Studio .NET)

  2. Place the XSD files in the Common7\Packages\schemas\xml directory.

  3. The following step is optional, the only difference is for people who prefer the xslt template to contain the xsl: prefixes, you will need to modify the xslt files that ship with VS.NET.

  4. Place the xslt file in the Common7\IDE\NewFileItems directory. This will also fix the existing stylesheet (it was missing the xsl prefix). A backup has been provided with the zip file.

  5. You may also have to go find two other locations that the xslt file may be placed:
    • If you have VB.NET installed, you will need to also replace the xslt file in the Vb7\VBWizards\XSLTFile\Templates\xxxx folder. xxxx being any numbered folder, 1033 is the us folder and so on. If you have multiple folders, you will need to replace the item in each of those folders.

    • If you have C# installed, you will need to also replace the xslt file in the VC#\CSharpProjectItems folder.

Now when you add an xslt file to a project as we did in the beginning of this article and you begin to type your xslt statements you will see intellesense drop downs appear as shown below. 

XsltTr6.jpg 

In summary the .NET IDE is very extendable via macros and schemas if you use them to their fullest potential.  This article was intended to demonstrate how easy it is to add needed functionality like xslt transformations to the .NET IDE.  A logical next step would be to make the macro into an add-in to allow for added features like enhanced UI for a better user experience.

Up Next
    Ebook Download
    View all
    Learn
    View all