Mvp.Xml Project: EXSLT.NET module

EXSLT.NET is a community-developed implementation of the EXSLT extensions to the XSLT 1.0 for the .NET platform. EXSLT.NET fully implements the following EXSLT modules: In addition EXSLT.NET provides a proprietary set of useful extension functions. Find full list of supported extension functions and elements in the "Extension Functions and Elements" section. For more info about EXSLT and EXSLT.NET see References.

1. What's New In This Version

  • EXSLT.NET now works with new .NET 2.0 XSLT processor - XslCompiledTransform class
  • ExsltTransform class has been deprecated, please use MvpXslTransform instead
  • Support for fractional seconds in EXSLT Dates and Times functions
  • Performance improvements

2. Usage

Typically you are using EXSLT.NET module in your application via Mvp.Xml.Common.Xsl.MvpXslTransform class, which encapsulates EXSLT implementation:

using System;
using System.Xml.XPath;
using Mvp.Xml.Common.Xsl;

public class ExsltTest
{  
  public static void Main()   
  {
    MvpXslTransform xslt = new MvpXslTransform();
    xslt.Load("foo.xsl");
    xslt.Transform(new XmlInput("foo.xml"), 
      new XmlOutput("result.html"));
  }
}

Additionally MvpXslTransform class has two properties - SupportedFunctions and MultiOutput, which allow you to control which features should be supported, for instance you can define that you need all extension function modules, but not multiple output support (the default settings) by setting SupportedFunctions and MultipleOutput properies in your code before the call to the Transform() method:

xslt.SupportedFunctions = ExsltFunctionNamespace.All;
xslt.MultiOutput = false;

Note: You can find more information about practical usage of the EXSLT.NET in the "Building Practical Solutions with EXSLT.NET" article at the MSDN XML Developer Center.

It's also possible to use EXSLT.NET in XPath-only environment. For doing that one makes use of Mvp.Xml.Exslt.ExsltContext class:

XPathExpression expr = nav.Compile("set:distinct(//author)");
expr.SetContext(new ExsltContext(doc.NameTable));
XPathNodeIterator authors = nav.Select(expr);
while (authors.MoveNext())    
  Console.WriteLine(authors.Current.Value);

See "EXSLT Meets XPath" article for more information.

3. Extension Functions and Elements

Full list of extension functions EXSLT.NET supports can be found here.

Note: For compatibility, some extension functions (such as date:date-time()) have camelCased alias names, e.g. date:dateTime(). Both forms are equivalent names, referring to the same function implementation, although beware that alias names are non-standard ones, so most likely they won't be recognized by other EXSLT implementations.

The only extension element supported is the exsl:document element. See "Multiple Output" section for more info.

4. Multiple Output

EXSLT.NET partially supports exsl:document extension element. Not all exsl:document attributes and their values are supported in this version of the EXSLT.NET. The supported subset of attributes and values is as follows:
<exsl:document
    href = { uri-reference }
    method = { "xml" | "text" }
    encoding = { string }
    omit-xml-declaration = { "yes" | "no" }
    standalone = { "yes" | "no" }
    doctype-public = { string }
    doctype-system = { string } 
    indent = { "yes" | "no" } >
    <-- Content: template --> 
</exsl:document>

exsl:document extension element is not supported when transformation is done to XmlReader or XmlWriter. In the latter case use overloaded Transform() method, which accepts instance of MultiXmlTextWriter class to transform to.

exsl:document extension element is supported through postprocessing of transformation result using customized XmlTextWriter class. This unconditionally assumes the transformation is always done in XML, so actually currently there is no way to produce real HTML (not XHTML) result documents. More specifically, main result document is always XML, but subsidiary result documents may be written either as XML or as text, depending on the "method" attribute value of the appropriate exsl:document element.

Moreover, the xsl:output element is ignored. That only affects outputting of the main result document though, because the xsl:output element does not affect outputting of any subsidiary result documents. It's completely controlled by the exsl:document element. Instead, you can get some control over outputting of the main result document using the MultiXmlTextWriter properties inherited from the XmlTextWriter class, particularly with encoding and indentation.

Disabling of output escaping feature is ignored as always when XSL transformation is performed to an XmlWriter.

For more info about how it's implemented see "Producing Multiple Outputs from an XSL Transformation" article.

5. Support

You can get support using the following options:

6. References

  1. EXSLT community initiative - http://www.exslt.org
  2. "EXSLT: Enhancing the Power of XSLT" by Dare Obasanjo, MSDN
  3. "EXSLT Meets XPath" by Dare Obasanjo, MSDN
  4. "Building Practical Solutions with EXSLT.NET" by Oleg Tkachenko, MSDN
  5. nxslt.exe - EXSLT.NET enabled command line XSLT utility.

Last edited Mar 11, 2007 at 9:48 PM by olegt, version 17

Comments

No comments yet.