XML and XSLT transformations becoming a large part of many business applications it would be beneficial to have this functionality in the Visual Studio .NET IDE. Following are the instructions for adding XSLT transformations and Intellisense to XSLT documents to the Visual Studio .NET IDE.
This additional functionality is achieved by implementing a macro written in VB.NET and a schema that depicts the hierarchical 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 intellisense when working with XSLT documents.
Loading and Using the Macro
- Creating a demo project:
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.
- Navigate to the Tools->Macros->Load Macro Project menu item as shown above and open the macro project included in the zip file called
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.
- 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.
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.
Adding xslt Intellisense to Visual Studio .NET
Now that we know we can transform XSLT documents inside the Visual Studio .NET IDE it would be nice to get Intellisense 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.
- Locate your Microsoft Visual Studio .NET installation folder. (The default location is Program Files\Microsoft Visual Studio .NET)
- Place the XSD files in the Common7\Packages\schemas\xml directory.
- 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 Visual Studio .NET.
- 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.
- 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 Intellisense drop downs appear as shown below:
In summary the Visual Studio .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 Visual Studio .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.
- First revision - 28th January, 2003.