Hidden Undocumented Feature of Visual Studio 2008 - Dynamic XSLT Intellisense

| 12 Comments | 1 TrackBack

A very little known fact is that Visual Studio 2008 does support real XSLT intellisense - not a static XSLT schema-based one, but real dynamic intellisense enabling autocompletion of template names, modes, parameter/variable names, attribute set names, namespace prefixes etc.

For some obscure reason it is off by default and obviously completely undocumented. I'll show you how to turn it on. But before - a little teaser.

1. When you about to call a named template you are presented with a list of all named templates in your stylesheet. My favorite feature. Finally you don't have to remember all your template names:

2. In XSLT template parameters are passed by name, so when you call a template and want to pass parameters you actually have to know exactly what parameter names are. And you better know them for sure, because if you make a mistake you pass a parameter with wrong name you get no error or even warning. XSLT 1.0 specification allows such nonsense.  That's why template parameter name autocompletion is a real time saver:

3.  You can pass parameters when applying templates too. Obviously due to dynamic XSLT processing model it's hard to know in advance which template will be matched at run time, so it's hard to suggest list of parameter names. In this version of XSLT intellisense we get list of all parameters used in all templates, filtered by mode. I believe XML Tools could optimize it a bit by filtering the list when it's clear from the context which template will be matched. Anyway, very useful:

4. Autocompletion of template modes is also extremely useful. Make mistake in mode name and you can spend hours in debugger trying to figure out why your template isn't matched, because again this is not an error or even something wrong according to XSLT spec. That's why this is so cool:

5. Finally a couple of useful namespace prefix autocompletions. exclude-result-prefixes now becomes easier:

and <xsl:namespace-alias> (mostly used for generating XSLT using XSLT):

6. If you use <xsl:attribute-set> elements, you will be happy to see this one:

 

These are autocompletions I'm currently aware of. There might be more - it's currently completely undocumented and I probably the first one writing about this feature. For example key names are collected too, but I haven't found where they are used. If you happen to discover another XSLT autocompletion, report it in comments section please.

And finally how to turn this awesomeness on:

Yes, regedit. Create String value called "XsltIntellisense" under "HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\XmlEditor" key. "True"/"False" are valid values.

If you are too lazy for editing registry manually, here is XsltIntellisense.reg file you can run (but rename it to .reg before).

If you don't want to mess with registry, wait till tomorrow. I'm going to release IronXSLT v0.3, which will turn XSLT intellisense on for you while installing.

Enjoy!

Related Blog Posts

1 TrackBack

TrackBack URL: http://www.tkachenko.com/cgi-bin/mt-tb.cgi/742

12 Comments

Does this wok with custom XSD .
I have custom Schema., It would be nice if VS could sense the path

@Martin Kool
Thanks for the registry-hint

CACuzcatlan, I think you need VS 2008 SP1 for this feature.

I haven't been able to get this working. I'm using Visual Studio Team System 2008 on a Vista 64 machine. I added the key, restarted VS, even restarted the computer, but nothing works. Tried it with both XSL and XSLT extensions. Do I have to do anything after updating the registry values?

One more hidden XSLT feature VS 2008 SP1 has is XSLT Hierarchy.
It is controlled by setting XsltImportTree to True in HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\XmlEditor.
It adds imports/includes in form of tree inside the 'Solution Explorer' window.
This is the only way to open 'Build-in Rules.xsl' autogenerated file.

One more topic also to look at is insert snippet and surround snippet for xslt
works so good. If you write about this, will help lots of xslt and xml developers.

One more topic also to look at is insert snippet and surround snippet for xslt
works so good. If you write about this, will help lots of xslt and xml developers.

This feature seems to work only only if you have no xsl:includes. If you have xsl:includes it will autocomplete only the templates that are in your includes and ignore any in your style sheet.

Hi,

Is there any difference using keys in xslt 2.
As for me the keys written work properly in xslt 1 but doesn't work in xslt2.

Let me know if there is any change.

Thanks,

It actually does work for the XSL extension, even for any extension that you choose as long as your contents is an xsl stylesheet.

For users that have Visual Studio Web Developer (the free express edition), this trick works too but with a different regkey:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\VWDExpress\9.0\XmlEditor]
"XsltIntellisense"="True"

Except of the namespace related ones XMLSpy has those intellisense features too for XSLT. Even more the modes are filtered and you have all of the template names, parameters and modes available in a nice docking outline window also.

This only works if your file extension is XSLT and not XSL.

Leave a comment