New XSLT stylesheet template in Visual Studio 2008 (again)

| 1 Comment | 1 TrackBack

When you create new XSLT stylesheet in Visual Studio via project (Add/New Item) or globally (File/New/File aka Ctrl+N), you start with template content. This template is changing in every new Visual Studio version, probably because every new generation of developers working on XSLT tools in Visual Studio have different vision about what you should start with.

Let's see. Visual Studio 2003. Pure simplicity:

<?xml version="1.0" encoding="UTF-8" ?>
<stylesheet version="1.0" xmlns="">

Visual Studio 2005 has two different templates for new XSLT stylesheet (!). When you create it via project you get the same as above empty stylesheet template. But if you go via Ctrl+N you get this fancy template:

<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="1.0"

<xsl:template match="/">
        This is an XSLT template file. Fill in this area with the
        XSL elements which will transform your XML to XHTML.


Yes, believe it or not, but some Microsoft developers were sure you should start with EXSLT namespace declaration in your stylesheet. The fact is that .NET 2.0 introduced partial native support for EXSLT, but it was never documented. It's still hidden portability gem.

Now what you get in Visual Studio 2008:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl=""
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="@* | node()">
            <xsl:apply-templates select="@* | node()"/>

No more EXSLT, back to basics - proprietary nonportable MSXSL namespace by default. This is sad.

Beside this weird proprietary comeback it's interesting that this new template contains identity transformation rule. This cumbersome looking <xsl:template> is the base of data transformation filtering. It processes every single node in source document recursively and outputs it as is.  By adding more template rules you can override base behavior to add, remove or modify particular nodes. Very powerful technique. This is smart choice for new file template.

Related Blog Posts

1 TrackBack

TrackBack URL:

1 Comment

Thanks for commenting on our work.
Entire story on XSLT templates was longer and more complicated. Beside Ctrl+N (File | New) you can also add new XSLT to project.
Each project type in VS has its own set of templates and most of them are different from each other in VS 2005.
Important part of this change is unification.

Interesting aspect of default template in VS 2005 is that it talks about transforming “XML to XTML” but output it produces would not be XHTML 
It is not clear who wrote it and why it declares EXSLT namespace. This was done by somebody outside of XML team.

XslCompiledTransform (and VS as a result) don’t support EXSLT natively so we removed it.
We added declarations for MSXSL namespace. Declaration itself doesn’t hurt your portability, but allows VS to provide Intellisense for msxsl:script and other extension elements.

Identity template is a handy thing to have for both experience and novice developers.

Enjoy it.

Leave a comment