XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition (784 page)

BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
5.7Mb size Format: txt, pdf, ePub
ads

Summary

XSLT 2.0 is not 100% backward compatible with version 1.0. Most stylesheets will convert with no changes at all, but a few will need tweaking. Moving a large application from XSLT 1.0 to 2.0 is an exercise that needs to be carefully planned, with detailed regression testing carried out to catch any obscure corner cases that might not show up immediately with the first few test runs.

Appendix D

Microsoft XSLT Processors

This appendix contains summary information about Microsoft's XSLT processors.

At the time of writing, Microsoft does not yet have an XSLT 2.0 processor, so the information in this appendix all relates to its XSLT 1.0 products. In view of this, I am not including a comprehensive specification of Microsoft's APIs, merely an outline of their structure. The reference information can be found in Microsoft's own documentation, or in books that concentrate on XSLT 1.0 processing.

The best information available on Microsoft's future plans comes in a blog posting released just after XSLT 2.0 was finalized, at
http://blogs.msdn.com/xmlteam/archive/2007/01/29/xslt-2-0.aspx
. All this really does is to confirm that Microsoft has a development team in place to work on an implementation, but this represents a significant turnaround given that two years earlier Microsoft was saying it thought XQuery would meet all the requirements, and more recently that the way forward was its proprietary
Linq to XML
language. It's likely to be 2009 at the earliest before we see a full product release, though hopefully there will be previews earlier than this.

The announcement suggests Saxon on .NET as an interim solution. A recommendation from Microsoft is not something I would have dared to hope for when I started out on the project!

Microsoft offers two families of products, with completely different APIs. The XSLT processor in the MSXML family comes as standard with Internet Explorer, though it is also available as a freestanding component and is delivered as part of the Office suite. In the current Microsoft jargon, this runs “on the native stack”, that is, it is compiled into machine code and calls the Windows APIs, rather than relying on the .NET platform. More recently, the
System.Xml.Xsl
package has become available as part of the .NET framework. This appendix gives a brief outline of both these product families.

In the early days it was frequently reported that MSXML was faster than the .NET processor, and that it conformed more closely to the W3 C specifications. As far as I can tell, neither of these criticisms is now valid. Both processors offer excellent performance, and few serious conformance issues are reported for either product (the main one being MSMXL's cavalier attitude toward whitespace).

MSXML

MSXML is a package that includes a number of core XML technologies: XML parsing with SAX and DOM interfaces, XSLT transformation, and XML Schema validation. Microsoft has released several versions of the product. The original beta version 1.0 was quickly superseded by version 2.0, which was supplied with the final release of Internet Explorer 5.

MSXML3 became a production release in October 2000 and was included as a standard part of Internet Explorer 6. You will sometimes see it referred to as MSXSL, that being more accurately the name of a command line interface which is available as a free MSDN download.

MSXML4, 5, and 6 followed, with fairly minor enhancements as far as the XSLT part of the product was concerned. However, MSXML3 is still in use, partly because of the installed base of IE6 users, and partly because it was the last version that retained support for Microsoft's obsolete WD-xsl dialect. WD-xsl was first shipped in 1998 before XSLT 1.0 was finalized, and you still occasionally come across stylesheets written in this variant of the language: you can recognize them because they use the namespace URI
http://www.w3.org/TR/WD-xsl
.

You can find download links for MSXML by going to
http://msdn.microsoft.com/xml
. The current version of the Software Development Kit (SDK) includes support for MSXML versions 3, 4, 5, and 6, recognizing that many developers need to test with multiple versions of the runtime.

The objects, methods, properties, and events available with the MSXML3 parser are listed in the Help file that comes with the SDK. I have only included here the parts of the interface that are relevant to XSLT and XPath processing.

Objects

The objects of particular interest to XSLT and XPath processing are listed below:

Object
Description
IXMLDOMDocument
The root of an XML document
IXMLDOMNode
Any node in the DOM
IXMLDOMNodeList
A collection of
Node
objects
IXMLDOMParseError
Details of the last parse error that occurred
IXMLDOMSelection
A selection of nodes
IXSLProcessor
An execution of an XSLT stylesheet
IXSLTemplate
A compiled XSLT stylesheet in memory

These objects are described in the sections that follow.

IXMLDOMDocument and IXMLDOMDocument2

The
IXMLDOMDocument
class inherits all the properties and methods of
IXMLDOMNode
.
IXMLDOMDocument2
is a later version of the interface, introducing a few extra properties and methods. This section lists the additional methods and properties of relevance to XSLT and XPath processing, in other words, all the methods and properties that are not also present on
IXMLDOMNode
, which is described on page 1150.

Additional Methods

The methods particularly relevant to XPath and XSLT processing are described in detail below.

The
validate()
and
setProperty()
methods actually belong to the
IXMLDOMDocument2
interface, which is an extension to
IXMLDOMDocument
introduced with MSXML version 2.6.

Name
Returns
Description
abort
(Nothing)
When a document is being loaded asynchronously,
abort()
can be called at any time to abandon the process.
load
Boolean
Loads document from the specified XML source. The argument is normally a string containing a URL. Clears out any existing content of the
Document
object, and replaces it with the result of parsing the XML source. Returns
True
if successful,
False
otherwise.
loadXML
Boolean
Loads the document from a string containing the text of an XML document. Clears out any existing content of the
Document
object, and replaces it with the result of parsing the XML string. Returns
True
if successful,
False
otherwise.
save
(Nothing)
Saves the document to a specified destination. The destination is usually a filename, given as a string. The effect is to serialize the
Document
in XML format as a file. It is also possible to specify various other objects as a destination, for example, it can be another
Document
object, in which case the document is duplicated.
setProperty
(Nothing)
Sets various system properties. The most important properties are:
  • SelectionLanguage
    . This takes the value
    XPath
    (the MSXML4 default) or
    XSLPattern
    (the default for MSXML3). This affects the syntax used in the expression passed to the
    selectNodes()
    and
    selectSingleNode()
    methods. If you want to use XPath 1.0 syntax you must set this property to
    XPath
    . The value
    XSLPattern
    refers to the old Microsoft-specific WD-xsl dialect.
  • SelectionNamespaces
    . The value of this property should be a space-separated list of namespace declarations, for example:

xmlns:a=“http://a.com/” xmlns:b=“http://b.com/”

These define the namespace prefixes that can be used within any expression passed to the
selectNodes()
and
selectSingleNode()
methods.

validate
(Nothing)
Validates the document, using the current DTD or schema.
BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
5.7Mb size Format: txt, pdf, ePub
ads

Other books

Tomb of Atlantis by Petersen, Christopher David
London Harmony: Minuette by Erik Schubach
No Place by Todd Strasser
Loving Lies by Lora Leigh
Lover's Kiss by Dawn Michelle
Attempting Normal by Marc Maron
The Two Koreas: A Contemporary History by Oberdorfer, Don, Carlin, Robert
Murder in Store by DC Brod