May 5, 2005

Declarative way to expose methods as XSLT extension functions?

I had a conversation with somebody about how EXSLT.NET worked around the hyphenated EXSLT function names problem and if there are better ways to solve it. Here is a suggestion for Microsoft: give us more control over exposing .NET methods as extension functions and make it declarative. ...

Currently when one exposes an object as an extension object to XSLT, all its public instance and static methods become accessible as XSLT extension functions. One has no control over which methods are exposed and which aren't. Also one has no control over how object methods are exposed to XSLT:

  • no custom name, so you call a function in XSLT by its CLR name, while XSLT and CLR functions syntax requirements and naming conventions are fairly different - hence aforementioned EXSLT.NET problem: many EXSLT functions are named in XSL style - names contain hyphens, but in .NET method names cannot contain them. As a consequence in EXSLT.NET we had to resort to a MSIL level hacking.
  • no control over marshalling between CLR and XSLT type systems, which are very different
  • no control over memoization (result caching)
  • no control over code access - security is binary-grained - everybody having FullTrust can use an extension object and nobody else
  • no overrides or priority means as in XSLT 2.0 stylesheet functions
  • no arguments optionality
  • no control over function namespace. Think about it - namespace, extension function belongs to is defined not by a person who implements it, but by someone who uses it.
When working with Web Services .NET doesn't expose every public method of your class as WebMethod, right? Instead Web methods should be marked with WebMethodAttribute, which along with bunch of other attributes controls exposing Web Service interface. Wouldn't it be nice to see the same declarative approach applied to XSLT extension objects? I mean something like
/// <summary>
/// Calculates the circumference of a circle given the radius.
/// </summary>
[XsltExtensionObject(Namespace="http://example.com/calculate")]
public class Calculate
{
    private double circ = 0;

    [XsltExtensionFunction(Name="circumference", Memoization=true)]
    public double Circumference(double radius)
    {
      circ = Math.PI*2*radius;
      return circ;
    }
 }
Benefits are evident, aren't they? You would say - dream on, who cares? Ok, but I believe that such stuff is inevitable as XML penetrates to the core of modern programming languages such as C# or Java.

Oh well, I filed above as a suggestion to the MSDN Product Feedback Center, go vote for it if you like the idea. Any comments would be appreciated too.

May 4, 2005

.NET 2.0 prohibits DTD in XML by default

Yep, no DTD is allowed by default in the .NET 2.0 Beta2: XmlReaderSettings.ProhibitDtd Property (System.Xml) Gets or sets a value indicating whether to prohibit document type definition (DTD) processing. Return Value true to prohibit DTD processing; otherwise false. The default is true. Remarks This setting can be useful in preventing ...

May 3, 2005

Changing value of an XSLT variable (don't laugh!)

Can one change a value of a variable in XSLT? Unexpected answer - yes, when debugging XSLT in Visual Studio 2005 Beta2. I'm not sure even if it's a bug. Actually it can be quite useful when debugging to be able to change some values, right? Do other XSLT debuggers ...

XML Tools in Visual Studio 2005 video from the Channel 9

Finally something interesting from the Channel 9: Ken Levy shows new cool XML tools in Visual Studio 2005 - improved XML editor, XML Intellisense, schemas, XML code snippets, XSLT editing and debugging etc etc etc. 41 min video, still worth watching. ...

May 2, 2005

Microsoft licensed Mvp.Xml library

On behalf of the Mvp.Xml project team our one and the only lawyer - XML MVP Daniel Cazzulino aka kzu has signed a license for Microsoft to use and distribute the Mvp.Xml library. That effectively means Microsoft can (and actually wants to) use and distribute XInclude.NET and the rest Mvp.Xml ...

May 1, 2005

Erik Meijer on Helping Programmers Program Better

Erik Meijer, one of designers of Haskell98 and C-omega languages will be presenting an interesting webcast at Tuesday, May 03, 2005 10:00 AM (GMT-08:00): MSDN Webcast: Language Design: Helping Programmers Program Better (Level 300) One of the greatest challenges programmers face is translating the concepts in their head into a ...

XQuery in .NET 2.0 Petition - too late, guys!

Almost 6 months after it's been announced that Microsoft won't ship XQuery implementation in the .NET 2.0, StylusStudio (maker of the namesake XML IDE) decided to run an online petition "XQuery for all" to urge Microsoft change the mind. Well, as a marketing action it's ok, but the petition itself ...