12.5. Commercial XSLT Processors

As noted, we are only describing three commercial XSLT processors due to limits of space and the simple pragmatics of how widespread and commonly used they are. These three processors are Sun Microsystem's XSLTC, Oracle's XML suite, and Microsoft's MSXML.

12.5.1. Sun Microsystems' XSLTC

Sun Microsystems' XSLTC (XSLT Compiler) is a unique addition to the XSLT processor realm in that it produces translets per stylesheet, which greatly reduce the amount of memory consumed by the DOM, in most cases, and often substantially increase speed. It is also possible to protect your stylesheet composition with the Sun translets, as they are compiled byte-code rather than human-readable XML document instances. This approach brings the promise of sophisticated transformations with a small enough memory footprint to work with wireless devices. This very new technology is significantly different from a conventional XSLT processor.

The latest tests at Sun show that XSLTC is typically 30% faster, if not more, than XT. The following table (provided by Sun) of some contributed XSL stylesheets shows a sample of processing speeds.

 XSLTC XT Saxon Xalan
test1 2.3 2.76 3.96 6.16
test2 2.1 2.98 4.4 5.98
test3 2.98 4 4.26 14.1
test4 4.18 4.72 6.3 12.48
test5 3.74 5.78 5.82 10.1
test6 4.7 7.5 6.6 11.84
test7 2.08 4.5 3.98 7.22

12.5.2. Oracle® XML Developer's Kit (XDK)

Oracle provides a suite of XML tools in its XML Developer's Kit (XDK), which is available for Java, C, C++, and PL/SQL. This suite includes an XML parser and an XSLT processor, as well as other useful XML tools. XSLT support is provided with version 2 of the XML parser, which can be downloaded from the Oracle Technology Network Web site at http://technet.oracle.com/tech/xml. The Oracle XDK is free, and it is fully supported for Oracle customers who have an existing support plan. Anyone using the Oracle XDK can also take advantage of free technical assistance provided through the XML Discussion Forum on Oracle Technet. The XDK can also be redistributed under the terms of the Oracle license.

The Oracle XML Parser is available in a standalone command-line version, or Libraries for Java, C, C++, and PL/SQL. It supports DOM2, SAX2, XML Namespaces 1.0, and XML Schema, and also runs on Oracle 8i and Oracle Application Server.

The XSLT processor supports the W3C XSLT Recommendation 1.0 and the W3C XPath Recommendation 1.0.

12.5.3. Installing the Oracle XSL Processor

The XSLT processor is included with the XML parser download. The Oracle XML parsers can be downloaded from the Oracle Technology Network Web site at http://technet.oracle.com/tech/xml. Select the appropriate XDK language version, and then click on the “Software” icon.

Note

You must be a registered Oracle Technology Network member to have access to download software. Membership is free, but you may have to fill out a registration form prior to downloading software.


Software version choices are listed in Table 12-1

Table 12-1. Software for XSLT and Oracle
Software Platform
Java v2 UNIX, Windows NT
C Linux, Sun Solaris, Windows NT
C++ v2 Linux v2.0.2, Sun Solaris v2.0.4, HP Unix, Windows NT v2.0.3
PL/SQL UNIX, Windows NT

The appropriate programming environment for each version should be installed and configured prior to installing the parser. For example, if you download the Java version, Java JDK-1.1.x or higher should be installed on your system. Also, since the files are zipped, either GNU gzip on UNIX or the WinZip executable on Windows should be available to unzip the files.

Once the appropriate software is installed and the zipped parser file has been downloaded, unzip the file into a directory of your choice and configure your system to add the directory and parser to your PATH and CLASSPATH environment variables.

The Oracle XSL processor has a command line utility as well as libraries. The download includes sample files. The command to run the XSL processor on the sample files is:

java oracle.xml.parser.v2.oraxsl <sample xsl file> <sample xml file>

12.5.4. Microsoft® MSXML

The October 2000 Microsoft XML Parser (MSXML) 3.0 final release provides a complete implementation of XSLT/XPath and complete conformance to the specifications from the W3C and the OASIS Test Suite.[4]

[4] There are a few minor bugs in this release, which Microsoft is addressing with Web releases.

Complete implementation of XSLT/XPath is of course the key. Previous versions of the Microsoft Parser did not support certain elements and functions of the XSLT and XPath specifications. The specific changes in this release include support for the <xsl:decimal-format> element, the unparsed-entity-uri() and format-number() functions, and the namespace axis.

Microsoft's original implementation of MSXML (for Internet Explorer® 5) contained functionality that was not implemented in the final XSLT or XPath specifications. However, those ideas contributed to the development of a new W3C Proposal, XML Query Language (XQL),[5] and also led to the creation of a new W3C working group, the XML Query group.

[5] See http://www.w3.org/TandS/QL/QL98/pp/xql.html.

MSXML 3.0 continues to support the previous XSL language WD-XSL,[6] which integrated the XQL extensions. Since this language is obsolete, Microsoft encourages people to move to compliant XSLT as soon as practical.

[6] See http://www.w3.org/TR/WD-xsl.

The Microsoft web site provides complete documentation for XSLT, XML, and SAX2, including MSXML extensions. The documentation is included in the installation for the 3.0 Version of the XML SDK and can be downloaded from:

http://msdn.microsoft.com/xml/default.asp
XML Downloads → XML → MSXML SDK 3.0 Release

The files are installed in the Program FilesMicrosoft XML Parser SDK folder on your system. The documentation is in the Docs directory, and can be accessed by clicking on the xmlsdk30.chm file.

12.5.4.1. MSXML Extension Elements and Functions

The Microsoft XSLT Processor extends the XSLT and XPath specifications with one extension element, <msxsl:script>, and one extension function, node-set().

The <msxsl:script> Extension Element

The <msxsl:script> extension element is a top-level element (a child of <xsl:stylesheet> or <xsl:transform>) and contains script blocks that define global variables and functions for script extensions. It has two attributes: language, which is used to specify the scripting language of the script block it contains; and implements-prefix, a required attribute used to associate a namespace prefix with the script block, as shown in the following element model definition. The <msxsl:script> element does not allow child elements.

<!-- Category: extension top---level element -->
<msxsl:script
  language = "language-name"
  implements---prefix = "prefix of user's namespace">
</msxsl:script>

Calling the script function using the <xsl:value-of> instruction element executes the script block and converts the result into a text string. The select attribute of the <xsl:value-of> element passes in the parameters required by the function. The script blocks defined by <msxsl:script> are globally available to all XSLT elements.

The optional language attribute specifies the active scripting language for the function defined in the script block. It accepts the same values that are allowed on the <script> element in HTML. The processor uses the default language Microsoft JScript® if no other language is specified, or if the attribute is not specified.

The required implements-prefix attribute is used to associate a namespace prefix with the script block. The namespace must be declared prior to the use of the <msxsl:script> element. The value of the attribute is the prefix declared by the namespace.

Example 12-2 comes directly from the Microsoft SDK[7] documentation, and shows an example of the declaration of the user namespace, as well as the declaration and calling of a script block.

[7] Much of the information for this section comes directly from the Microsoft SDK 3.0 documentation. All copyrights for Microsoft and the MSXML, as stated in the copyright page of the SDK, apply.

Example 12-2. Using the <msxsl:script> function.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                 xmlns:msxsl="urn:schemas---microsoft---com:xslt"
                 xmlns:user="http://mycompany.com/mynamespace"
                 version="1.0">
      <msxsl:script language="JScript" implements---prefix="user">
        function xml(nodelist) {
          return nodelist.nextNode().xml;
        }
       </msxsl:script>

       <xsl:template match="/">
         <xsl:value---of select="user:xml(.)"/>
       </xsl:template>
</xsl:stylesheet>

12.5.4.2. The node-set() Extension Function

The MSXML node-set() function enables the conversion of a tree into a node set. The result is a single node that contains the root node of the tree. The function return type of this function is a node-set. Its one required argument is a string, as shown in the function prototype below. The string is processed in a manner defined by the msxsl namespace to convert the string into a node-set. The function must be called using the msxsl namespace prefix, unless the msxsl prefix is declared to be the default namespace of the stylesheet.

Function: node-set msxml:node-set (string)
Function NameFunction GroupFunction Return Type ArgumentsArgument Type
node---set() Node-set Node-set String Required

One of the features that was removed from the original MSXML implementation, in order to support conformance, was the ability to use variable references in pattern expressions. Because you cannot use variable references in a pattern, it is not possible to have arbitrary patterns that return a node-set. For example, the use of the $var variable in <xsl:for-each select="$var/el"> is not allowed, but the node-set() function gets around this limitation, as shown below:

<xsl:for-each select="msxsl:node-set($var)/el)">

The result of the evaluation of the select expression is a node-set consisting of <el> nodes which are descended from whatever element is defined in the var variable. The content of the <xsl:for-each> element will then apply to each node in the node-set.

12.5.5. Installing the Latest Microsoft XML Parser

Download the current version of MSXML from the Microsoft Web site at:

http://msdn.microsoft.com/xml/default.asp
XML Downloads → XML → MSXML Parser 3.0 Release

The Download screen will appear n the window on the right hand side. Click on the “Download” icon, accept the end-user license agreement, and select “save to disk.” This will install a file called “msxml3.exe” on your system. Double click on this file to install the software. Note: You must have the Microsoft Windows Installer version 1.1 loaded on your machine prior to running this installation. It can be downloaded from the same window that was used to download the MSXML parser, but may already be included in your system if you have the latest version of Microsoft Office or Windows NT. The installer will run and install the program, but will not tell you where or how to use it.

Installing the 3.0 version will not overwrite any previous versions of MSXML on your system unless it is installed specifically using the “replace” mode. This means that your programs will continue to use the older version of the parser until you replace it with the new version using the xmlinst.exe installer tool, which can be downloaded from:

http://msdn.microsoft.com/xml/default.asp
XML Downloads → XML → Xmlinst.exe Installer Tool.

The Microsoft web site recommends installing Internet Explorer 4.01 Service Pack 1 or later in order for this beta release to function properly. The latest version of Internet Explorer can be downloaded from:

http://www.microsoft.com/windows/ie/default.htm

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset