Is XSLT dead in Microsoft world?

Back in 2001 I was in TechEd Barcelona where Microsoft unveiled Sharepoint and .NET 1.o. I remember like yesterday when Don Box was demoing WebServices from bathtub (SOAP) and coding c# from MacBook in Microsoft event!.

Anyway, after seeing Microsoft’s plan for following years I decided fully focus on Microsoft Technology. I saw first SharePoint which I think sucked. WebServices weren’t interesting either it just felt a bit too hairy for doing simple things. But what I loved was the whole concept of ASP.NET, C# and XML. After seeing XSLT in action I knew this is going to be my language, and it was. Well at least until now. XSLT is really great for templating websites, I gone through many tempalting engines but nothing beats good old XML/XSLT transformations. It is simple and fast. Well, it can get complex sometimes but usually when XSLT gets complex it means you are doing something wrong. Then it’s time to stop and think. Maybe, this is faster in code-behind or perhaps maybe it’s a good idea to write XSL -helper in code-behind for this.

I have to say, I have never come comfortable building sites from .NET controls basically because it was producing bad html markup-up and I don’t have full control how to build html on it but Microsoft has made it better over the time and nowadays it even produces valid mark-up. But still, I have to compile a DLL when making small updates. This is where XSLT rocks!

Because of this, I have waited (.NET 1.1)… and I have waited (.NET 2.0-3.5)… but there hasn’t been XSLT 2.0. Recently I read blog post in XML.com from M. David Peterson I am quoting him who quotes Microsoft XML Team’s WebLog : Chris Lovett Interview

“As for XSLT 2.0 – we’ve heard from customers and understand the improvements in XSLT 2.0 over XSLT 1.0, but right now we’re in the middle of a big strategic investment in LINQ and EDM for the future of the data programming platform which we think will create major improvements in programming against all types of data.”

DAMN!

Bad news for me… Now with all MVC/LINQ/WEB2.0 stuff… Isn’t XML cool anymore?

Sorting Sitecore data to multicolumn html table

Sorting Sitecore data to multicolumn html table is quite hard in XSLT because data in XML is not sorted by item/@sortorder.

I finally found out how to do this so it will actually work and I am not loosing data. The trick is creating data first into a flat XML Nodeset and looping this data then to a multicolumn table using following-sibling::item commands. Here is the small sample code for this where I take abstract content structure from the Sitecore to a XML Nodeset <ul><li>xxxxxx</li></ul>.

First let’s make a variable.

<xsl:variable name=”keywords”>
<ul>
<xsl:for-each select=”$keywords”>
<xsl:for-each select=”descendant-or-self::item[(@template=’keywords’)]”>
<li>
<xsl:value-of select=”sc:fld(‘text’,.)”/>
</li>
</xsl:for-each>
</xsl:for-each>
</ul>
</xsl:variable>

Then using msxsl:node-set -function (http://msdn2.microsoft.com/en-us/library/hz88kef0(vs.71).aspx) I create nodeset out of the XSL variable and loop data to the html table.

<table>
<xsl:for-each select=”msxsl:node-set($keywords)/ul/li[position() mod 3 = 1]”>
<tr>
<td>
<xsl:value-of select=”.”/>
</td>
<xsl:for-each select=”following-sibling::li[position() < 3]”>
<td>
<xsl:value-of select=”.”/>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>

I would be very keen to know if you have done this in pure XSLT because msxsl:node-set seems to be quite slow.

Converting xsl:variable to nodeset

The msxsl:node-set function enables you to convert a result tree fragment into a node set. The resulting node set always contains a single node and is the root node of the tree.

<xsl:variable name="books">
<book author="Michael Howard">Writing Secure Code</book>
<book author="Michael Kay">XSLT Reference</book>
</xsl:variable>

<authors>
<xsl:for-each select="msxsl:node-set($books)/book">
<author><xsl:value-of select="@author"/)</author>
</xsl:for-each>
</authors>

Saxonica

Saxonica is the new home of the Saxon XSLT and XQuery processor developed by Michael Kay. Saxonica undertakes the development of the Saxon XSLT, XQuery, and XML Schema processor.

It will take a long while before we see XSLT 2.0 from Microsoft. Therefore, for anyone who wants to play with XSLT 2.0 and XQuery, download SAXON from Sourceforge. I heard it works nicely with .NET.

Saxon XSLT meets C#

Saxon.NET – v.8.0-B port to C# This could very easily prove the foundation technology to get XSLT 2.0 onto Windows in a major way. While not perfect, XSLT 2.0 is considerably less verbose, easier to build extensions and capable of group filtering and manipulation far in excess of what version XSLT 1.0.

Boost XSLT with Extension Objects

XSLT is my favourite language when developing web application, thought XSLT does not contain all the power found in languages such as C# or VB.NET. In situations where you need to perform functions that XSLT cannot handle in its own, you can resort to XSLT extension objects.

I have been working last months on group calendaring application and there I have face huge problems with dates. How to format dates on XSLT? Version 1.0 of XSLT doesn?t support sorting dates using the xsl:sort tag. This can present a problem since dates frequently play an important role in my calendar application. Now I just need to figured out how this one work. ?