InfoQ

News

The End of XSLT for .NET Programmers?

Posted by Jonathan Allen on Mar 05, 2008 06:03 AM

Community
.NET
Topics
XML Databinding
Tags
XSLT ,
Visual Basic.NET

Microsoft's VB team is starting a series of articles on how to use XML Literals. Many of these articles will demonstrate how to replace XSLT code with VB by making direct comparisons between the two languages.

XML Literals is a syntax first pioneered for Haskell and later brought to Microsoft for use in C#. Not finding a home in either language, the Visual Basic team snapped it up and made it a cornerstone of VB 9. This should not be too much of a surprise, as the Haskell syntax was heavily influenced by VBScript's inline HTML notation.

In the first XML Cookbook article, Doug Rothaus demonstrates the VB equivalents to XSLT's <xsl:copy-of>, <xsl:for-each>, <xsl:template>, <xsl:if>, <xsl:value-of>, and <xsl:attribute> elements. He also shows how to use XML Axis Properties in place of XPath.

Though the examples are simple, the VB versions are consistently shorter than the XSLT versions. Most of the gains are from moving away from XSLT's rather verbose syntax. Though not demonstrated here, VB also has an advantage in that you can call out to normal .NET code when needed.

Only VB though by Francois Ward Posted Mar 5, 2008 8:53 AM
Re: Only VB though by Hartmut Wilms Posted Mar 5, 2008 9:08 AM
Another option is to use JavaScript / EcmaScript 4 XML (E4X) by Paul Fremantle Posted Mar 5, 2008 9:48 AM
microsoft's at it "again" by Miguel de Melo Posted Mar 7, 2008 3:09 PM
Re: microsoft's at it by Angus McDonald Posted Mar 9, 2008 4:52 PM
  1. Back to top

    Only VB though

    Mar 5, 2008 8:53 AM by Francois Ward

    XML literals are VB only though...so C# devs still go the old fashionned way (or with LINQ to XML i guess). Plus with XSLT, you have a standard reusable template, which will still be usuable the day we migrate from .NET to the "Next Big Thing(tm)". For simple, one shot operations, sure... but if you have a business critical transformation process, why would you do it in normal code?

  2. Back to top

    Re: Only VB though

    Mar 5, 2008 9:08 AM by Hartmut Wilms

    I have to agree with Francois, XSLT may be used in a myriad of ways. For instance XSLT can be used to transform artefacts within an MS Build script in order to generate code/XML/... from models. XSLT might also be used in conjunction with Web Services that rely on XML (messaging) rather than Code-First Web Services. Both use cases (and many more) are a natural way of handling XML and model transformations, independent of the implementation language. I would hate to see MS Build files cluttered with calls to VB code, which implements transformations ...

  3. I routinely use JavaScript/E4X (Wikipedia Entry) which is a standard extension to JavaScript. It is available in both the Rhino (Java) and SpiderMonkey (C) implementations of JS and means that you can embed simple XML scripting into many applications. It is also available in Adobe Flash, AIR, Acrobat and Flex. The Apache Synapse ESB allows you to use it as an alternative to XSLT when transforming XML messages, whether they are in a filesystem, JMS destination or coming via HTTP POST or GET. I have used it on many occasions and I also find it much simpler and more effective than XSLT. I've been using XSLT for 9 years now, and I still have to reach for the manual or samples. But I can write a short, sweet, simple E4X transform in minutes. If you are using the Rhino implementation, you can even replace the default XMLBeans-based parser implementation with one based on Apache Axiom which gives a significant performance boost. Finally, there is even an open source Mashup Server based on E4X. [Disclosure - I work for WSO2]

  4. Back to top

    microsoft's at it "again"

    Mar 7, 2008 3:09 PM by Miguel de Melo

    Surprise surprise, Microsoft just went out of their way to break yet another standard, and give it some fancy name. The so originally called "XML Literals" looks remarkably identical to the just W3C Standard XQuery, that the rest of the XML community have been working on so had together for years, to make sure it works for everyone, and so that we all agree on a common path. So I am not surprised they did it again, after all is part of Microsoft's philosophy, rip off what someone else is doing well, make it worse, and make a bucket out of it . . .

  5. Back to top

    Re: microsoft's at it

    Mar 9, 2008 4:52 PM by Angus McDonald

    Miguel, It's got nothing to do with XQuery. It simply makes XML literals behave as objects that Visual Basic code can interact with in a more feature-rich way than simple string literals. The VB team has combined that with the XML querying features of LINQ (which were designed to allow you to create an object interface to XML data files) to replace some of the operations XSLT allows. The point is that a Basic developer now can now use the full power of the language when working with XML. This is in no way an attack on XQuery, it's just that there is no need now for it when using Visual Basic as your language of choice. Cheers, Angus

Educational Content

Bindings, Platforms, and Innovation

This presentation focuses on the Internet and separating myth from fact, history from the future, and the mundane from the imaginative. Bob Frankston presents a vision of what could and should be.

Orchestrating Long Running Activities with JBoss / JBPM

This article explores the use of JBoss and jBPM to implement design solutions that effectively address the issue of orchestrating long running activities.

Neo4j - The Benefits of Graph Databases

This presentation covers the use of graph databases as an optimal solution for data that is difficult to fit in static tables, rapidly evolving data or data that has a lot of optional attributes.

Realistic about Risk: Software development with Real Options

This session introduces Real Options and shows how it can help in running your project. Real Options is a decision-making process that can be used to manage risk.

Communication Flexibility Using Bindings

This article discusses the use of bindings on services and references (including the instance of non-configured bindings) as the means to implement SCA communications in a Web and SOA environment.

Writing DSLs in Groovy

After a short introduction to DSLs, Scott Davis plays with the keyboard showing how to approach the creation of a DSL by typing working snippets of Groovy code that get executed.

Scaling Agile with C/ALM (Collaborative Application Lifecycle Management)

IBM Rational and InfoQ present, Scaling Agile with C/ALM, an eBook showing organizations how to become “finely tuned software delivery machines” by enabling team integration and scaling.

Concurrent Programming with Microsoft F#

Amanda Laucher presents a real life enterprise application written in F#. She shows actual code snippets, explaining design decisions and suggesting how to use some of the F# constructs.