Database Reference
In-Depth Information
XSLT
XQuery is a powerful language, but there are tasks that can be solved just as well with
XSLT, and sometimes even more easily. For instance, for complex XML transforms
you can either use XQuery (with typeswitch constructions) or XSLT. Whether
transformations are more easily achieved in XQuery or XSLT is a contentious issue,
with many experts firmly preferring one over the other. Fortunately eXist supports
both, so you may decide for yourself which you find easier. The most basic examples
of using XSLT in eXist can be found in “Hello XSLT” on page 33 .
For executing XSLT, eXist 2.1 uses Saxon HE (Home Edition) version 9.4.0.7 by
default. If you need to upgrade to Saxon's commercial PE (Professional Edition) or
EE (Enterprise Edition), you can replace the existing Saxon libraries in
$EXIST_HOME/lib/endorsed with their respective PE or EE counterparts and the
accompanying license file. If you need a different XSLT processor, you can configure
it in $EXIST_HOME/conf.xml .
An important consequence of using an external XSLT processor (and not one that is
truly part of the eXist core) is that XSLT scripts run in isolation from the rest of the
environment. The documents the XSLT processor works on are passed wholesale, but
their database context (most importantly, indexes) is lost. No index-based query opti‐
mization is performed. So, be careful in designing the interaction between XQuery
and XSLT: it's best to leave the querying to your XQuery scripts and use XSLT for
transformation only.
Embedding Stylesheets or Not
Stylesheets can be fully embedded in your XQuery code. Example 10-1 shows an
XQuery script that runs an embedded stylesheet for checking the XSLT system prop‐
erty information (and can find out whether the Saxon version changed in the eXist
version you're using).
Example 10-1. Get the XSLT processor information
xquery version "1.0" encoding "UTF-8" ;
declare option exist:serialize "method=html media-type=text/html indent=no" ;
declare variable $ page-title as xs:string := "XSLT processor information" ;
declare variable $ xslt as document-node () := document {
<xsl:stylesheet version = " 2.0 " xmlns:xsl = " http://www.w3.org/1999/XSL/Transform "
xmlns:xs = " http://www.w3.org/2001/XMLSchema "
xmlns:fn = " http://www.w3.org/2005/xpath-functions "
exclude-result-prefixes = " #all " >
Search WWH ::




Custom Search