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 Question: Is Microsoft Working On An XSLT 2.0 Processor? Answer 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.”
Bad news for me… Now with all MVC/LINQ/WEB2.0 stuff… Isn’t XML cool anymore?
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.
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.
<xsl:for-each select=”msxsl:node-set($keywords)/ul/li[position() mod 3 = 1]“>
<xsl:for-each select=”following-sibling::li[position() < 3]“>
I would be very keen to know if you have done this in pure XSLT because msxsl:node-set seems to be quite slow.
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.
<book author="Michael Howard">Writing Secure Code</book>
<book author="Michael Kay">XSLT Reference</book>
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.
In MSDN there is an article about Transforming Word Documents into the XSL-FO Format. The article introduces WordprocessingML and XSL-FO vocabularies and shows how to transform Word documents to into XSL-FO.
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.
Good to remember… Read and cry.
Of course you could use an extension function such as http://www.exslt.org/dyn/functions/evaluate/ to change string to nodeset for dynamic xml lookup.
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. ?
I just found nice little application called XsltMajic Profiler Tool that helps you Performance Tune an XSLT Style Sheet in Visual Studio .NET Using System.Xml. Microsoft has also nice informatic video at Microsoft Knowledge Base. This tool is really worth of checking out if you are working with XML/XSL on .NET.