XSLT used to get all the girls, now it is just a washed up junkie ;-)
Don't flame me yet. I don't think XSLT is really a washed up junkie, but I do have to say that people have really chosen to make extended use almost any other XML technology just to avoid using XSLT. Or do they just not realize how powerful XSLT really is? When XSLT first came out, XML was an infant. There weren't any documents available in XML and you couldn't just go grab some XML data off the web. Now, just about everything is available in XML. Just to take a small look at my machine:
Visual Studio Project Files, Visio documents, various configuration files, and all of my RSS data. Looking out on the web, you can call an good number of web services to get data, download XML documents from all over the place, get your banking data in XML, download government data in XML, and now you can even code in XML (XAML, Xamlon, WFML, etc...)
Even though most of this stuff is available in XML, you still aren't seeing a great deal of XSLT in practical use. XSLT is an anything to anything type of processing langauge and I love it for being so flexible. Remember those VS project files. Well, I can convert them to my own custom makefile format in seconds. Why wait for build tools in Whidbey? Visio documents? I can convert those into any format I see fit, I can even use the XSLT to just do basic *searches* and output the nodes only containing my criterion. RSS data? Well, RSS Bandit handles that one for me, but if it didn't, oooh, I'd be so on that.
As for all the rest of the data that is available, I think people really are missing the power of XSLT when it comes to processing. Everyone wants to use an XmlDocument (DOM) or a XmlDataReader. Everyone wants to do a bunch of custom parsing so they can print out results. Is XSLT such a mythical beast that most people don't think the learning curve is worth tackling for the reward? It can be daunting with all of the strange rules that don't harbor any likeness towards traditional computer programming languages. But I think any user is capable of taking XSLT by the horns and doing a quick and dirty.
I'm going to say, I want to see more XSLT stuff out there. I was going to sit down and write a 100 liner that demonstrated compiling WFML. I think instead I'm going for a 5 liner in code, and an XSLT style sheet so you can customize how your WFML gets translated into actual code. You see, XSLT is that powerful. It can consume XML in just about any format, and spit out the relavent code for it, without the need for a complex, hand-written processor. (I'm the perf guy, and yes I know it is slow, but this is the one time I'm not doing 1 billion iterations of something ;-)
// The holy grail of programs. This uses any transform on a document to produce RESULTS!
private static void Main(string[] args) {
XslTransform transform = new XslTransform();
transform.Load(args[0]);
transform.Transform(args[1], args[2]);
}
Here is a simple XSLT for translating the references in the project system. It translates both assembly references and project references (I think).
<xsl:template match="VisualStudioProject/CSHARP/Build/References">
<xsl:for-each select="Reference[@AssemblyName]">
<xsl:if test="@AssemblyName">
<xsl:value-of select="@AssemblyName" /><xsl:text>.dll</xsl:text>
</xsl:if>
<xsl:if test="@Project">
<xsl:value-of select="@Name" /><xsl:text>\$(_BUILDDIR)\</xsl:text><xsl:value-of sele
ct="@Name" /><xsl:text>.dll</xsl:text>
</xsl:if>
<xsl:if test="position() != last()"><xsl:text>,</xsl:text></xsl:if>
</xsl:for-each>
<xsl:text>
</xsl:text>
</xsl:template>
Note all of the cool <xsl:text> elements I have to use for newlines. That is a pain, but I never do use the entity replacement stuff. My loss right? And finally, a small partial script that translates a Visio document into a table (truncating for brevity here). Note the use of the really cool element/attribute XSLT processing attributes. These can save you so much time. Often you need something more dynamic than what they offer and you need to hand-gen the tags yourself, but those are rare circumstances.
<xsl:output method="html" encoding='ISO-8859-1'/>
<xsl:template match="VisioDocument/Pages/Page/Shapes">
<xsl:for-each select="Shape[Prop/@Name='Tag']">
<xsl:sort select="Text" />
<xsl:element name="tr">
<xsl:attribute name="bgcolor">#E8E8E8</xsl:attribute>
<xsl:element name="td">
<xsl:attribute name="align">center</xsl:attribute>
<xsl:value-of select="Text" />
</xsl:element>
<xsl:element name="td">
<xsl:attribute name="align">center</xsl:attribute>
<xsl:value-of select="Prop[@Name='Type']/Value" />
</xsl:element>
<xsl:element name="td">
<xsl:attribute name="align">center</xsl:attribute>
<xsl:value-of select="Prop[@Name='Mfg']/Value" />
</xsl:element>
<!-- Truncated -->
Most XSLT projects can be completed on the order of 50% faster than their equivalent hand-coded counter-parts. They are also great for rapid development and quick searching XML documents using simple XPath queries. I can't count the number of times a little bit of XSLT has gone a long way. This is a tribute, so hats off!