<?xml-stylesheet href="../make-menu.xsl?cache=20260710" type="text/xsl"?>
<html>
<head>
 <this-is section="technology" page="xslt-and-xquery" subpage=""/>
 <title>Saxonica: XSLT and XQuery</title>
 <meta name="title" content="Saxonica: XSLT and XQuery"/>
 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
 <meta name="description" content="contains introduction to XML, XSLT and XQuery"/>
 <meta name="keywords" content="XML, XSLT, XQUERY, PUBLICATIONS, W3C" />
 <meta name="coverage" content="Worldwide"/>
 <meta name="copyright" content="Copyright Saxonica Ltd"/>
 <meta name="robots" content="index, follow"/>

</head>
<body class="main">
  
<h1>Introduction to XSLT and XQuery</h1>

<p>Saxonica specializes in XSLT and XQuery technology. If you're new to these 
languages, this page tries to explain briefly what these languages are and why
you would want to use them.</p>

    
    <div id="fixed-aside">
        <h2>On this page:</h2>
        <ul>
            <li><a href="#xslt" class="title">XSLT: styling and transformation</a></li>
            <li><a href="#xslt2" class="title">XSLT 2.0 and schema-aware transformation</a></li>
            <li><a href="#xquery" class="title">XQuery: the query language for XML</a></li>
            <li><a href="#xpath" class="title">XPath</a></li>               
        </ul>
        <br/>
        <h2>See also:</h2>
        <ul>
            <li><a href="introducing-xml.xml">Introduction to XML</a></li>
            <li><a href="questions.xml">Answers to frequently asked questions</a></li>
            <li><a href="publications.xml">Our publications</a></li>
            <li><a href="w3c.xml">W3C conformance information</a></li>
        </ul>
    </div>
   
 
    <a id="xslt" class="anchor"/>
<h2>XSLT: styling and transformation</h2>

    <p><b class="definition">XSLT</b> stands for <i>eXtensible Stylesheet Language - Transformation</i>. 
    XSLT transforms (or changes) an XML document according to instructions specified in an XSLT stylesheet 
    so that a single source or set of source documents can be used to produce output in a number of possible formats, for example:</p>
    <ul>
        <li>HTML which can then be rendered by a browser</li>
        <li>a database load file</li>
        <li>data formatted for a typesetting driver such as postscript or PDF</li>
        <li>other, different XML documents (e.g. you're a publisher who wants to publish at the British Library - you need to use their tag set)</li>
        <li>flat text (ASCII) or CSV, to import into a piece of software.</li>
    </ul>
    <p>
    The language was
designed primarily for writing stylesheets that enable XML documents to be displayed
to their readers. By writing more than one stylesheet, you can display the same information
in different ways to different audiences, and tailor the presentation to the capabilities
of different display devices, including web browsers, conventional print media, handheld
devices, and digital TV. </p>
    
    <p>By authoring your information in XML, and rendering it using XSLT,
you separate the tasks of the content author and the graphic designer, and you ensure
that a uniform design is achieved across all your content. This approach also allows you to
change the visual design without rewriting the content.</p>

<!-- The example below is out of date. Should it be replaced? DL 2014-11-26 -->

<!--<p>To see an example of this in action,
compare the Saxon documentation <a class="bodylink" href="../documentation/documentation.xml">on this site</a>
with the <a class="bodylink" href="https://saxon.sourceforge.net/saxon7.9.1/index.html">earlier version</a> 
of the same material: the only difference is a 400-line stylesheet written in XSLT.</p>-->

<p>XSLT is also used increasingly for <b>transforming</b> data. For example, if you need to
send electronic orders to your suppliers, then the XML message used for this purpose will have
to conform to a schema agreed with the suppliers. If the data starts life in an Excel spreadsheet,
you can export it in XML using the built-in capabilities of Excel, and then transform it
to the format required by the agreed schema, by means of an XSLT transformation.</p>

<p>XSLT 1.0 was defined by the World Wide Web Consortium (W3C) in 1999. Saxon was one of 
the first implementations. Many others followed, including products from major vendors such
as Microsoft, Oracle, and IBM. Despite this competition, the Saxon XSLT 1.0 processor was downloaded nearly 200,000 times,
as well as being bundled with many other software products. It featured
regularly in the list of the top 100 open-source software products on the SourceForge site.</p>

<p>XSLT 2.0 followed in 2007, and Saxon led the way in implementing the standard, which
offers immense improvements in functionality and productivity over the original version. Many of the XSLT 1.0 implementations (for example, those from Microsoft) dropped out of the race, confirming Saxon's leadership position. In 2012 Saxonica produced Saxon-CE, which was not only the first-ever
implementation of XSLT 2.0 able to run in the browser, but also the first to handle user interaction as well as pure batch transformation.</p>
    
    <a href="#top" class="top-of-page"><p>Return to top of page</p></a>
 
    <a id="xslt2" class="anchor"/>
<h2>XSLT 2.0 and schema-aware transformation</h2>

<p>The specifications for XSLT 2.0 reached the status of a W3C Recommendation in January 2007,
    after a lengthy development process. Throughout this process, regular new Saxon releases
    were produced implementing the new features of successive drafts of the specification.
    This gave the user community the opportunity to try out new features before they were
    frozen, and to give feedback to the working groups developing the language. As editor
    of the specification and developer of Saxon, Michael Kay was especially well-placed to ensure
    that the users' voice was heard.
 </p>

<p>XSLT 2.0 added many new features desperately needed by existing users. These include more
powerful facilities for handling text (regular expressions) and structured data (grouping), which
greatly increase the range of tasks to which XSLT can be applied, especially when converting 
legacy data and document formats to XML.</p>

<p>One of the most significant additions was that XSLT became <b>schema-aware</b>. This means that the XML
Schema used to define the source and result documents of a transformation can now be used to guide
the compilation and execution of the stylesheet. This makes stylesheet code more robust, it speeds
the debugging cycle, and it creates the potential for significant performance improvements.</p>

<p>Saxon was the first processor to implement the XSLT 2.0 specification and remained in this position
    for some time. Today it has been joined by commercial implementations from vendors such as
    IBM, Intel, Altova, and MarkLogic, but it remains the most mature of the available products,
    valued by users for its performance, its usability, its obsession with standards conformance, and its useful range of vendor extensions. 
    Saxon is now available in three versions: an open source
product, Saxon-HE, and an entry-level commercial product Saxon-PE which both implement the conformance requirements for a <i>Basic XSLT Processor</i>,
and the enterprise product, Saxon-EE, which adds the extra features of a <i>Schema-Aware XSLT Processor</i>.</p>

<p>Since XSLT 2.0 was finalized in 2007, the W3C Working Group has turned its attention to the
    development of XSLT 3.0, and once again Saxon is in the lead implementing new features
    as they emerge. The focus in XSLT 3.0 is on streaming transformations (transforming large documents
    without first reading them into memory in their entirety), and many of the new features to
    enable this have been productized in the 9.x series of Saxon-EE releases.</p>
    
    <a href="#top" class="top-of-page"><p>Return to top of page</p></a>
 
    <a id="xquery" class="anchor"/>
<h2>XQuery: the query language for XML</h2>

<p><b class="definition">XQuery</b> is another language specification from W3C, produced in parallel with XSLT 2.0. 
    
    XQuery is a query language for XML documents. Whereas XSLT
    was designed primarily for document rendition, and does data transformation almost as a sideline, XQuery
    was conceived as a language for querying XML databases, in the same way as SQL is used for querying
    relational databases.</p>
    
    <p>It can be used to extract information from one or more XML documents, for example:</p>
    <ul>
    <li>Show all the books published by National Geographic</li>
    <li>What is the average price of books with "Harry Potter" in the title?</li>
    <li>Sort the books by author within each category.</li>
    </ul>
    
    <p> All the major relational database vendors are adding XML support to their existing
products, and new <i>Native XML Databases</i> are also appearing. These products all use XQuery to access
the data.</p>

<p>Like XSLT, XQuery can also be used to transform XML messages from one format to another. The language
is less powerful than XSLT 2.0, but usability studies have shown that it is easier for users to learn, and
there are also indications that it is easier for vendors to optimize.</p>
    
    <p>XQuery 3.0 is now a W3C Recommendation, and Saxon is achieving a 100% pass rate in the evolving test suite
        (containing more than 25,000 separate tests).</p>

    <a href="#top" class="top-of-page"><p>Return to top of page</p></a>
    
    <a id="xpath" class="anchor"/>
<h2>XPath</h2>
<p>XQuery and XSLT have much in common. Both languages make use of <b class="definition">XPath</b>, a syntax for finding your way
around the structure of an XML document and it can also be used directly from programming languages such as Java and C#. 

It is also used within other W3C languages such as XML Schema and XForms. Both languages share the same data model and type system, and the
same function library, which means that the two languages can work together well in a single application.
For example, you can use XQuery to extract data from an XML database, and XSLT to present the results to
users on the web.</p>

    <a href="#top" class="top-of-page"><p>Return to top of page</p></a>
 
</body>
</html>
