Tips, tricks and all the info about Microsoft Visual Studio 2008

XML and XSLT in Visual Studio 2008

, posted: 23-Feb-2009 09:00

Visual Studio 2008 has some great support for debugging XML and XSLT. It is not a well-known piece of functionality but it is there and although simple it does its job well.

XSLT is not a difficult technology to grasp but when you don’t have a decent IDE to back you up debugging can be long and painful and impair productivity.

In this article I’ll cover off the very basics and provide a few useful tips.

A Simple Example

Here's a simple example. I have a piece of XML that defines some static content:

I want to do is render this page as HTML. The XSLT looks like this:

After opening each of these in Visual Studio 2008, you’ll notice an “XML” top-level menu. Clicking this will give you the options of debugging the transformation or showing the output.


XML file selected

XSLT file selected

Selecting “Debug XSLT” will display an Open File dialog letting you select the other file to complete the transformation. For example, if you have an XML file selected then you will select an XSLT file for the transformation.

The output will be:

(The parameter value hasn’t been picked up in this instance, but I’ll get to that shortly.)

Along the way you’ll get many of the usual debugging aids you are used to; stepping and value inspection.

And that’s all there is to it, really.

Tip #1 XML or XSLT First?

Whether you start with the XML or the XSLT you end up with transformed XML. The IDE remembers the second file selected so you can repeat the transformation.  Unless you close the first file you do not get a chance to reselect the second file to complete the transformation.

If you have one example of XML but several XSLTs then select each XSLT first. As you initiate each transformation for the first time select the same XML file. Each time you modify the XSLT or XML you can simply re-run the transformations.

In the opposite scenario when you have you have one XSLT and multiple XML examples select each XML and when given the option select the XSLT file.

Tip #2 Including XSLT

Your solution may end up using several XSLT files some of which may be dependent on others.

Be aware that Visual Studio resolves such dependencies without you having to do anything. When it comes to using these XSLTs in your application you will have to ensure that dependent XSLTs can get picked up.

Just for the record, use the XslCompiledTransform class and call the Transform method.

public void Transform(
  XmlReader input,
  XsltArgumentList arguments,
  XmlWriter results,
  XmlResolver documentResolver)

You will have to derive a class from XmlResolver with appropriate logic to locate any additional XSLTs.

Tip #3 Parameters Workaround

When it comes to passing parameters to an XSLT you have a little more work to do.

Place a breakpoint at the start of the XSLT and start debugging. In your Locals window the parameter will show up letting you edit the value.

When the appropriate element is reached this will pick up your edited parameter value.

Tip #4 Ignore the times in the Output window

After running a transformation two times are shown in the Output window.

Ignore both of these. The load time isn’t really all that important and the execution time is misleading.

When you work with XSLT in the .NET Framework (2.0 and later) you'll be using the XslCompiledTransform class. This class compiles the XSLT into IL and then jitters it on its first run. Visual Studio repeats this process in its entirety each time. Your application however, will probably take advantage of the compiled nature of the class and all transformations thereafter will only take one or two milliseconds.


•    Visual Studio 2008 has some lightweight, but effective support for developing XML and XSLT.
•    Choosing whether to debug XML or XSLT can be an important choice for productivity.
•    Parameters can be achieved.
•    The final XSLT will transform faster in your application than in the IDE.

Further Reading

Intellisense for XSLT: As I was putting this post together I came across this article. Although I haven’t implemented this myself it looks good for productivity. I'll investigate further at some point, you may want to as well.

Profiling XSLT: If you are lucky enough to have the Developer Edition of Visual Studio 2008 there is a profiler add-in that you can add to Visual Studio. This article covers the profiler in detail. This is well worth pursuing if your solution has a lot of XSLT you think may be a bottleneck.

Download Visual Studio 2008 90 day trial
For detailed information and to request a free 90-day trial DVD of Visual Studio 2008 Team Suite to be sent out to you, go to the Microsoft Visual Studio webpage.

About the Author
Scott is a C# developer. He takes great pleasure in producing more business value for less code.

He’s always on the look-out for better and more elegant ways of doing things and uses these in any one of the dozen or so side-projects he has on the go. Genuinely appreciates being told better ways of doing things and actively seeks such criticism. (technical) (personal) (a work in progress that isn’t working)

Other related posts:
The New Zealand ALM Conference 2011 (Application Life Cycle Management)
Writing your own Html Helpers for the ASP.NET MVC Framework
Automating Visual Studio 2008

About the Visual Studio 2008 Blog

In the years since the hugely successful release of Visual Studio 2005, Microsoft has used developer feedback from all over the world to introduce over 250 new features in the 2008 release.

This sponsored blog will bring Visual Studio 2008 tips and tricks from well known developers in the Australian and New Zealand tech community directly to you.

Make sure you bookmark this blog or subscribe to our RSS feed.

Other blog posts

The New Zealand ALM Conference...
Writing your own Html Helpers ...
Automating Visual Studio 2008...
Windows Azure Table Storage - ...
Windows Azure Table Storage - ...
Introduction to New SQL Server...
Using the Visual Studio 2008 P...
Getting started with Windows A...
Why consider sitting for an MC...
Unit testing .Net Compact Fram...

Some recent comments

Praveen M on Visual Studio 2008 support for building SilverLigh: I installed SILVERLIGHT TOOLS for VS2008 at my work. I am able to do silverlight...

zefo on Unit testing with Visual Studio 2008: Just minor recommendation: better use *.png for the screenshots. Jpeg is more su...

gil ziny on Unit testing with Visual Studio 2008: When I associate the unit test with TFS testing policy, if fails during check-in...

lynette on Visual Studio 2008 JavaScript Debugging: i have enable in IE the ability to debug scripts. if i go to my section in my c...

Junkie on Why consider sitting for an MCTS or MCP Certificat: The way you presented the case for certification has been completely different f...

Brian Link on Unit testing with Visual Studio 2008: You seem to be incorrect in one of your opening remarks - it seems that web.conf...

Dipanwaya on Unit testing .Net Compact Framework applications w: Steps Behind the Test in the VS 2008? How to test a module in the VS 2008 Envir...

Ricardo on Visual Studio 2008 support for building SilverLigh: Yes! Found the solution myself :) Reset the environment of Visual Web Developer...

Ricardo on Visual Studio 2008 support for building SilverLigh: Have the same problem after installing Visual Web Developer 2008 SP1 and Silverl...

kjward on Automating Visual Studio 2008: thanks lots for all the great info. i'm sure the answer to my question is in th...


The Visual Studio 2008 blog is sponsored by Microsoft NZ. The blog posts are the authors' genuine accounts of their experiences with Visual Studio 2008 and are not influenced or filtered by Microsoft NZ in any way.