"Fossies" - the Fresh Open Source Software Archive

Member "libxslt-1.1.34/doc/internals.html" (30 Oct 2019, 28836 Bytes) of package /linux/www/libxslt-1.1.34.tar.gz:

The requested HTML page contains a <FORM> tag that is unusable on "Fossies" in "automatic" (rendered) mode so that page is shown as HTML source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 <?xml version="1.0" encoding="ISO-8859-1"?>
    2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    3 <html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /><style type="text/css">
    4 TD {font-family: Verdana,Arial,Helvetica}
    5 BODY {font-family: Verdana,Arial,Helvetica; margin-top: 2em; margin-left: 0em; margin-right: 0em}
    6 H1 {font-family: Verdana,Arial,Helvetica}
    7 H2 {font-family: Verdana,Arial,Helvetica}
    8 H3 {font-family: Verdana,Arial,Helvetica}
    9 A:link, A:visited, A:active { text-decoration: underline }
   10     </style><title>Library internals</title></head><body bgcolor="#8b7765" text="#000000" link="#a06060" vlink="#000000"><table border="0" width="100%" cellpadding="5" cellspacing="0" align="center"><tr><td width="120"><a href="http://swpat.ffii.org/"><img src="epatents.png" alt="Action against software patents" /></a></td><td width="180"><a href="http://www.gnome.org/"><img src="gnome2.png" alt="GNOME2 Logo" /></a><a href="http://www.w3.org/Status"><img src="w3c.png" alt="W3C logo" /></a><a href="http://www.redhat.com"><img src="redhat.gif" alt="Red Hat Logo" /></a><div align="left"><a href="http://xmlsoft.org/XSLT/"><img src="Libxslt-Logo-180x168.gif" alt="Made with Libxslt Logo" /></a></div></td><td><table border="0" width="90%" cellpadding="2" cellspacing="0" align="center" bgcolor="#000000"><tr><td><table width="100%" border="0" cellspacing="1" cellpadding="3" bgcolor="#fffacd"><tr><td align="center"><h1>The XSLT C library for GNOME</h1><h2>Library internals</h2></td></tr></table></td></tr></table></td></tr></table><table border="0" cellpadding="4" cellspacing="0" width="100%" align="center"><tr><td bgcolor="#8b7765"><table border="0" cellspacing="0" cellpadding="2" width="100%"><tr><td valign="top" width="200" bgcolor="#8b7765"><table border="0" cellspacing="0" cellpadding="1" width="100%" bgcolor="#000000"><tr><td><table width="100%" border="0" cellspacing="1" cellpadding="3"><tr><td colspan="1" bgcolor="#eecfa1" align="center"><center><b>Main Menu</b></center></td></tr><tr><td bgcolor="#fffacd"><form action="search.php" enctype="application/x-www-form-urlencoded" method="get"><input name="query" type="text" size="20" value="" /><input name="submit" type="submit" value="Search ..." /></form><ul><li><a href="index.html">Home</a></li><li><a href="intro.html">Introduction</a></li><li><a href="docs.html">Documentation</a></li><li><a href="bugs.html">Reporting bugs and getting help</a></li><li><a href="help.html">How to help</a></li><li><a href="downloads.html">Downloads</a></li><li><a href="FAQ.html">FAQ</a></li><li><a href="news.html">News</a></li><li><a href="xsltproc2.html">The xsltproc tool</a></li><li><a href="docbook.html">DocBook</a></li><li><a href="API.html">The programming API</a></li><li><a href="python.html">Python and bindings</a></li><li><a href="internals.html">Library internals</a></li><li><a href="extensions.html">Writing extensions</a></li><li><a href="contribs.html">Contributions</a></li><li><a href="EXSLT/index.html" style="font-weight:bold">libexslt</a></li><li><a href="xslt.html">flat page</a>, <a href="site.xsl">stylesheet</a></li><li><a href="html/index.html" style="font-weight:bold">API Menu</a></li><li><a href="ChangeLog.html">ChangeLog</a></li></ul></td></tr></table><table width="100%" border="0" cellspacing="1" cellpadding="3"><tr><td colspan="1" bgcolor="#eecfa1" align="center"><center><b>Related links</b></center></td></tr><tr><td bgcolor="#fffacd"><ul><li><a href="tutorial/libxslttutorial.html">Tutorial</a>,
   11           <a href="tutorial2/libxslt_pipes.html">Tutorial2</a></li><li><a href="xsltproc.html">Man page for xsltproc</a></li><li><a href="http://mail.gnome.org/archives/xslt/">Mail archive</a></li><li><a href="http://xmlsoft.org/">XML libxml2</a></li><li><a href="ftp://xmlsoft.org/">FTP</a></li><li><a href="http://www.zlatkovic.com/projects/libxml/">Windows binaries</a></li><li><a href="http://garypennington.net/libxml2/">Solaris binaries</a></li><li><a href="http://www.explain.com.au/oss/libxml2xslt.html">MacOsX binaries</a></li><li><a href="https://gitlab.gnome.org/GNOME/libxslt/issues">Bug Tracker</a></li><li><a href="http://codespeak.net/lxml/">lxml Python bindings</a></li><li><a href="http://cpan.uwinnipeg.ca/dist/XML-LibXSLT">Perl XSLT bindings</a></li><li><a href="http://www.zend.com/php5/articles/php5-xmlphp.php#Heading17">XSLT with PHP</a></li><li><a href="http://www.mod-xslt2.com/">Apache module</a></li><li><a href="http://sourceforge.net/projects/libxml2-pas/">Pascal bindings</a></li><li><a href="http://xsldbg.sourceforge.net/">Xsldbg Debugger</a></li></ul></td></tr></table><table width="100%" border="0" cellspacing="1" cellpadding="3"><tr><td colspan="1" bgcolor="#eecfa1" align="center"><center><b>API Indexes</b></center></td></tr><tr><td bgcolor="#fffacd"><ul><li><a href="APIchunk0.html">Alphabetic</a></li><li><a href="APIconstructors.html">Constructors</a></li><li><a href="APIfunctions.html">Functions/Types</a></li><li><a href="APIfiles.html">Modules</a></li><li><a href="APIsymbols.html">Symbols</a></li></ul></td></tr></table></td></tr></table></td><td valign="top" bgcolor="#8b7765"><table border="0" cellspacing="0" cellpadding="1" width="100%"><tr><td><table border="0" cellspacing="0" cellpadding="1" width="100%" bgcolor="#000000"><tr><td><table border="0" cellpadding="3" cellspacing="1" width="100%"><tr><td bgcolor="#fffacd"><h3>Table  of contents</h3><ul>
   12   <li><a href="internals.html#Introducti">Introduction</a></li>
   13   <li><a href="internals.html#Basics">Basics</a></li>
   14   <li><a href="internals.html#Keep">Keep it simple stupid</a></li>
   15   <li><a href="internals.html#libxml">The libxml nodes</a></li>
   16   <li><a href="internals.html#XSLT">The XSLT processing steps</a></li>
   17   <li><a href="internals.html#XSLT1">The XSLT stylesheet compilation</a></li>
   18   <li><a href="internals.html#XSLT2">The XSLT template compilation</a></li>
   19   <li><a href="internals.html#processing">The processing itself</a></li>
   20   <li><a href="internals.html#XPath">XPath expressions compilation</a></li>
   21   <li><a href="internals.html#XPath1">XPath interpretation</a></li>
   22   <li><a href="internals.html#Descriptio">Description of XPath
   23   Objects</a></li>
   24   <li><a href="internals.html#XPath3">XPath functions</a></li>
   25   <li><a href="internals.html#stack">The variables stack frame</a></li>
   26   <li><a href="internals.html#Extension">Extension support</a></li>
   27   <li><a href="internals.html#Futher">Further reading</a></li>
   28   <li><a href="internals.html#TODOs">TODOs</a></li>
   29   <li><a href="internals.html#Thanks">Thanks</a></li>
   30 </ul><h3><a name="Introducti2" id="Introducti2">Introduction</a></h3><p>This document describes the processing of <a href="http://xmlsoft.org/XSLT/">libxslt</a>, the <a href="http://www.w3.org/TR/xslt">XSLT</a> C library developed for the <a href="http://www.gnome.org/">GNOME</a> project.</p><p>Note: this documentation is by definition incomplete and I am not good at
   31 spelling, grammar, so patches and suggestions are <a href="mailto:veillard@redhat.com">really welcome</a>.</p><h3><a name="Basics1" id="Basics1">Basics</a></h3><p>XSLT is a transformation language. It takes an input document and a
   32 stylesheet document and generates an output document:</p><p align="center"><img src="processing.gif" alt="the XSLT processing model" /></p><p>Libxslt is written in C. It relies on <a href="http://www.xmlsoft.org/">libxml</a>, the XML C library for GNOME, for
   33 the following operations:</p><ul>
   34   <li>parsing files</li>
   35   <li>building the in-memory DOM structure associated with the documents
   36     handled</li>
   37   <li>the XPath implementation</li>
   38   <li>serializing back the result document to XML and HTML. (Text is handled
   39     directly.)</li>
   40 </ul><h3><a name="Keep1" id="Keep1">Keep it simple stupid</a></h3><p>Libxslt is not very specialized. It is built under the assumption that all
   41 nodes from the source and output document can fit in the virtual memory of
   42 the system. There is a big trade-off there. It is fine for reasonably sized
   43 documents but may not be suitable for large sets of data. The gain is that it
   44 can be used in a relatively versatile way. The input or output may never be
   45 serialized, but the size of documents it can handle are limited by the size
   46 of the memory available.</p><p>More specialized memory handling approaches are possible, like building
   47 the input tree from a serialization progressively as it is consumed,
   48 factoring repetitive patterns, or even on-the-fly generation of the output as
   49 the input is parsed but it is possible only for a limited subset of the
   50 stylesheets. In general the implementation of libxslt follows the following
   51 pattern:</p><ul>
   52   <li>KISS (keep it simple stupid)</li>
   53   <li>when there is a clear bottleneck optimize on top of this simple
   54     framework and refine only as much as is needed to reach the expected
   55     result</li>
   56 </ul><p>The result is not that bad, clearly one can do a better job but more
   57 specialized too. Most optimization like building the tree on-demand would
   58 need serious changes to the libxml XPath framework. An easy step would be to
   59 serialize the output directly (or call a set of SAX-like output handler to
   60 keep this a flexible interface) and hence avoid the memory consumption of the
   61 result.</p><h3><a name="libxml" id="libxml">The libxml nodes</a></h3><p>DOM-like trees, as used and generated by libxml and libxslt, are
   62 relatively complex. Most node types follow the given structure except a few
   63 variations depending on the node type:</p><p align="center"><img src="node.gif" alt="description of a libxml node" /></p><p>Nodes carry a <strong>name</strong> and the node <strong>type</strong>
   64 indicates the kind of node it represents, the most common ones are:</p><ul>
   65   <li>document nodes</li>
   66   <li>element nodes</li>
   67   <li>text nodes</li>
   68 </ul><p>For the XSLT processing, entity nodes should not be generated (i.e. they
   69 should be replaced by their content). Most nodes also contains the following
   70 "navigation" information:</p><ul>
   71   <li>the containing <strong>doc</strong>ument</li>
   72   <li>the <strong>parent</strong> node</li>
   73   <li>the first <strong>children</strong> node</li>
   74   <li>the <strong>last</strong> children node</li>
   75   <li>the <strong>prev</strong>ious sibling</li>
   76   <li>the following sibling (<strong>next</strong>)</li>
   77 </ul><p>Elements nodes carries the list of attributes in the properties, an
   78 attribute itself holds the navigation pointers and the children list (the
   79 attribute value is not represented as a simple string to allow usage of
   80 entities references).</p><p>The <strong>ns</strong> points to the namespace declaration for the
   81 namespace associated to the node, <strong>nsDef</strong> is the linked list
   82 of namespace declaration present on element nodes.</p><p>Most nodes also carry an <strong>_private</strong> pointer which can be
   83 used by the application to hold specific data on this node.</p><h3><a name="XSLT" id="XSLT">The XSLT processing steps</a></h3><p>There are a few steps which are clearly decoupled at the interface
   84 level:</p><ol>
   85   <li>parse the stylesheet and generate a DOM tree</li>
   86   <li>take the stylesheet tree and build a compiled version of it (the
   87     compilation phase)</li>
   88   <li>take the input and generate a DOM tree</li>
   89   <li>process the stylesheet against the input tree and generate an output
   90     tree</li>
   91   <li>serialize the output tree</li>
   92 </ol><p>A few things should be noted here:</p><ul>
   93   <li>the steps 1/ 3/ and 5/ are optional:  the DOM representing the
   94     stylesheet and input can be created by other means, not just by parsing
   95     serialized XML documents, and similarly the result tree DOM can be
   96     made available to other processeswithout being serialized.
   97   </li><li>the stylesheet obtained at 2/ can be reused by multiple processing 4/
   98     (and this should also work in threaded programs)</li>
   99   <li>the tree provided in 2/ should never be freed using xmlFreeDoc, but by
  100     freeing the stylesheet.</li>
  101   <li>the input tree created in step 3/ is not modified except the
  102     _private field which may be used for labelling keys if used by the
  103     stylesheet. It's not modified at all in step 4/ to allow parallel
  104     processing using a shared precompiled stylesheet.</li>
  105 </ul><h3><a name="XSLT1" id="XSLT1">The XSLT stylesheet compilation</a></h3><p>This is the second step described. It takes a stylesheet tree, and
  106 "compiles" it. This associates to each node a structure stored in the
  107 _private field and containing information computed in the stylesheet:</p><p align="center"><img src="stylesheet.gif" alt="a compiled XSLT stylesheet" /></p><p>One xsltStylesheet structure is generated per document parsed for the
  108 stylesheet. XSLT documents allow includes and imports of other documents,
  109 imports are stored in the <strong>imports</strong> list (hence keeping the
  110 tree hierarchy of includes which is very important for a proper XSLT
  111 processing model) and includes are stored in the <strong>doclist</strong>
  112 list. An imported stylesheet has a parent link to allow browsing of the
  113 tree.</p><p>The DOM tree associated to the document is stored in <strong>doc</strong>.
  114 It is preprocessed to remove ignorable empty nodes and all the nodes in the
  115 XSLT namespace are subject to precomputing. This usually consist of
  116 extracting all the context information from the context tree (attributes,
  117 namespaces, XPath expressions), and storing them in an xsltStylePreComp
  118 structure associated to the <strong>_private</strong> field of the node.</p><p>A couple of notable exceptions to this are XSLT template nodes (more on
  119 this later) and attribute value templates. If they are actually templates,
  120 the value cannot be computed at compilation time. (Some preprocessing could
  121 be done like isolation and preparsing of the XPath subexpressions but it's
  122 not done, yet.)</p><p>The xsltStylePreComp structure also allows storing of the precompiled form
  123 of an XPath expression that can be associated to an XSLT element (more on
  124 this later).</p><h3><a name="XSLT2" id="XSLT2">The XSLT template compilation</a></h3><p>A proper handling of templates lookup is one of the keys of fast XSLT
  125 processing. (Given a node in the source document this is the process of
  126 finding which templates should be applied to this node.) Libxslt follows the
  127 hint suggested in the <a href="http://www.w3.org/TR/xslt#patterns">5.2
  128 Patterns</a> section of the XSLT Recommendation, i.e. it doesn't evaluate it
  129 as an XPath expression but tokenizes it and compiles it as a set of rules to
  130 be evaluated on a candidate node. There usually is an indication of the node
  131 name in the last step of this evaluation and this is used as a key check for
  132 the match. As a result libxslt builds a relatively more complex set of
  133 structures for the templates:</p><p align="center"><img src="templates.gif" alt="The templates related structure" /></p><p>Let's describe a bit more closely what is built. First the xsltStylesheet
  134 structure holds a pointer to the template hash table. All the XSLT patterns
  135 compiled in this stylesheet are indexed by the value of the the target
  136 element (or attribute, pi ...) name, so when a element or an attribute "foo"
  137 needs to be processed the lookup is done using the name as a key.</p><p>Each of the patterns is compiled into an xsltCompMatch
  138 (i.e. an ''XSLT compiled match') structure. It holds
  139 the set of rules based on the tokenization of the pattern stored in reverse
  140 order (matching is easier this way). </p><p>The xsltCompMatch are then stored in the hash table, the clash list is
  141 itself sorted by priority of the template to implement "naturally" the XSLT
  142 priority rules.</p><p>Associated to the compiled pattern is the xsltTemplate itself containing
  143 the information required for the processing of the pattern including, of
  144 course, a pointer to the list of elements used for building the pattern
  145 result.</p><p>Last but not least a number of patterns do not fit in the hash table
  146 because they are not associated to a name, this is the case for patterns
  147 applying to the root, any element, any attributes, text nodes, pi nodes, keys
  148 etc. Those are stored independently in the stylesheet structure as separate
  149 linked lists of xsltCompMatch.</p><h3><a name="processing" id="processing">The processing itself</a></h3><p>The processing is defined by the XSLT specification (the basis of the
  150 algorithm is explained in <a href="http://www.w3.org/TR/xslt#section-Introduction">the Introduction</a>
  151 section). Basically it works by taking the root of the input document
  152 as the cureent node and applying the following algorithm:</p><ol>
  153   <li>Finding the template applying to current node.
  154     This is a lookup in the template hash table, walking the hash list until
  155     the node satisfies all the steps of the pattern, then checking the
  156     appropriate global template(s) (i.e.  templates applying to a node type)
  157     to see if there isn't a higher priority rule to apply</li>
  158   <li>If there is no template, apply the default rule (recurse on the
  159     children as the current node)</li>
  160   <li>else walk the content list of the selected templates, for each of them:
  161     <ul>
  162       <li>if the node is in the XSLT namespace then the node has a _private
  163         field pointing to the preprocessed values, jump to the specific
  164       code</li>
  165       <li>if the node is in an extension namespace, look up the associated
  166         behavior</li>
  167       <li>otherwise copy the node.</li>
  168     </ul>
  169     <p>The closure is usually done through the XSLT
  170     <strong>apply-templates</strong>construct, which invokes this process
  171       recursively starting at step 1, to find the appropriate template
  172       for the nodes selected by the 'select' attribute of the apply-templates
  173       instruction (default: the children of the node currently being
  174       processed)</p>
  175   </li>
  176 </ol><p>Note that large parts of the input tree may not be processed by a given
  177 stylesheet and that conversely some may be processed multiple times.
  178 (This often is the case when a Table of Contents is built).</p><p>The module <code>transform.c</code> is the one implementing most of this
  179 logic. <strong>xsltApplyStylesheet()</strong> is the entry point, it
  180 allocates an xsltTransformContext containing the following:</p><ul>
  181   <li>a pointer to the stylesheet being processed</li>
  182   <li>a stack of templates</li>
  183   <li>a stack of variables and parameters</li>
  184   <li>an XPath context</li>
  185   <li>the template mode</li>
  186   <li>current document</li>
  187   <li>current input node</li>
  188   <li>current selected node list</li>
  189   <li>the current insertion points in the output document</li>
  190   <li>a couple of hash tables for extension elements and functions</li>
  191 </ul><p>Then a new document gets allocated (HTML or XML depending on the type of
  192 output), the user parameters and global variables and parameters are
  193 evaluated. Then <strong>xsltProcessOneNode()</strong> which implements the
  194 1-2-3 algorithm is called on the docuemnt node of the input. Step 1/ is
  195 implemented by calling <strong>xsltGetTemplate()</strong>, step 2/ is
  196 implemented by <strong>xsltDefaultProcessOneNode()</strong> and step 3/ is
  197 implemented by <strong>xsltApplyOneTemplate()</strong>.</p><h3><a name="XPath" id="XPath">XPath expression compilation</a></h3><p>The XPath support is actually implemented in the libxml module (where it
  198 is reused by the XPointer implementation). XPath is a relatively classic
  199 expression language. The only uncommon feature is that it is working on XML
  200 trees and hence has specific syntax and types to handle them.</p><p>XPath expressions are compiled using <strong>xmlXPathCompile()</strong>.
  201 It will take an expression string in input and generate a structure
  202 containing the parsed expression tree, for example the expression:</p><pre>/doc/chapter[title='Introduction']</pre><p>will be compiled as</p><pre>Compiled Expression : 10 elements
  203   SORT
  204     COLLECT  'child' 'name' 'node' chapter
  205       COLLECT  'child' 'name' 'node' doc
  206         ROOT
  207       PREDICATE
  208         SORT
  209           EQUAL =
  210             COLLECT  'child' 'name' 'node' title
  211               NODE
  212             ELEM Object is a string : Introduction
  213               COLLECT  'child' 'name' 'node' title
  214                 NODE</pre><p>This can be tested using the  <code>testXPath</code>  command (in the
  215 libxml codebase) using the <code>--tree</code> option.</p><p>Again, the KISS approach is used. No optimization is done. This could be
  216 an interesting thing to add. <a href="http://www-106.ibm.com/developerworks/library/x-xslt2/?dwzone=x?open&amp;l=132%2ct=gr%2c+p=saxon">Michael
  217 Kay describes</a> a lot of possible and interesting optimizations done in
  218 Saxon which would be possible at this level. I'm unsure they would provide
  219 much gain since the expressions tends to be relatively simple in general and
  220 stylesheets are still hand generated. Optimizations at the interpretation
  221 sounds likely to be more efficient.</p><h3><a name="XPath1" id="XPath1">XPath interpretation</a></h3><p>The interpreter is implemented by <strong>xmlXPathCompiledEval()</strong>
  222 which is the front-end to <strong>xmlXPathCompOpEval()</strong> the function
  223 implementing the evaluation of the expression tree. This evaluation follows
  224 the KISS approach again. It's recursive and calls
  225 <strong>xmlXPathNodeCollectAndTest()</strong> to collect a set of nodes when
  226 evaluating a <code>COLLECT</code> node.</p><p>An evaluation is done within the framework of an XPath context stored in
  227 an <strong>xmlXPathContext</strong> structure, in the framework of a
  228 transformation the context is maintained within the XSLT context. Its content
  229 follows the requirements from the XPath specification:</p><ul>
  230   <li>the current document</li>
  231   <li>the current node</li>
  232   <li>a hash table of defined variables (but not used by XSLT,
  233       which uses its own stack frame for variables, described below)</li>
  234   <li>a hash table of defined functions</li>
  235   <li>the proximity position (the place of the node in the current node
  236   list)</li>
  237   <li>the context size (the size of the current node list)</li>
  238   <li>the array of namespace declarations in scope (there also is a namespace
  239     hash table but it is not used in the XSLT transformation).</li>
  240 </ul><p>For the purpose of XSLT an <strong>extra</strong> pointer has been added
  241 allowing to retrieve the XSLT transformation context. When an XPath
  242 evaluation is about to be performed, an XPath parser context is allocated
  243 containing an XPath object stack (this is actually an XPath evaluation
  244 context, this is a relic of the time where there was no separate parsing and
  245 evaluation phase in the XPath implementation). Here is an overview of the set
  246 of contexts associated to an XPath evaluation within an XSLT
  247 transformation:</p><p align="center"><img src="contexts.gif" alt="The set of contexts associated " /></p><p>Clearly this is a bit too complex and confusing and should be refactored
  248 at the next set of binary incompatible releases of libxml. For example the
  249 xmlXPathCtxt has a lot of unused parts and should probably be merged with
  250 xmlXPathParserCtxt.</p><h3><a name="Descriptio" id="Descriptio">Description of XPath Objects</a></h3><p>An XPath expression manipulates XPath objects. XPath defines the default
  251 types boolean, numbers, strings and node sets. XSLT adds the result tree
  252 fragment type which is basically an unmodifiable node set.</p><p>Implementation-wise, libxml follows again a KISS approach, the
  253 xmlXPathObject is a structure containing a type description and the various
  254 possibilities. (Using an enum could have gained some bytes.) In the case of
  255 node sets (or result tree fragments), it points to a separate xmlNodeSet
  256 object which contains the list of pointers to the document nodes:</p><p align="center"><img src="object.gif" alt="An Node set object pointing to " /></p><p>The <a href="http://xmlsoft.org/html/libxml-xpath.html">XPath API</a> (and
  257 its <a href="http://xmlsoft.org/html/libxml-xpathinternals.html">'internal'
  258 part</a>) includes a number of functions to create, copy, compare, convert or
  259 free XPath objects.</p><h3><a name="XPath3" id="XPath3">XPath functions</a></h3><p>All the XPath functions available to the interpreter are registered in the
  260 function hash table linked from the XPath context. They all share the same
  261 signature:</p><pre>void xmlXPathFunc (xmlXPathParserContextPtr ctxt, int nargs);</pre><p>The first argument is the XPath interpretation context, holding the
  262 interpretation stack. The second argument defines the number of objects
  263 passed on the stack for the function to consume (last argument is on top of
  264 the stack).</p><p>Basically an XPath function does the following:</p><ul>
  265   <li>check <code>nargs</code> for proper handling of errors or functions
  266     with variable numbers of parameters</li>
  267   <li>pop the parameters from the stack using <code>obj =
  268     valuePop(ctxt);</code></li>
  269   <li>do the function specific computation</li>
  270   <li>push the result parameter on the stack using <code>valuePush(ctxt,
  271     res);</code></li>
  272   <li>free up the input parameters with
  273   <code>xmlXPathFreeObject(obj);</code></li>
  274   <li>return</li>
  275 </ul><p>Sometime the work can be done directly by modifying in-situ the top object
  276 on the stack <code>ctxt-&gt;value</code>.</p><h3><a name="stack" id="stack">The XSLT variables stack frame</a></h3><p>Not to be confused with XPath object stack, this stack holds the XSLT
  277 variables and parameters as they are defined through the recursive calls of
  278 call-template, apply-templates and default templates. This is used to define
  279 the scope of variables being called.</p><p>This part seems to be one needing most work , first it is
  280 done in a very inefficient way since the location of the variables and
  281 parameters within the stylesheet tree is still done at run time (it really
  282 should be done statically at compile time), and I am still unsure that my
  283 understanding of the template variables and parameter scope is actually
  284 right.</p><p>This part of the documentation is still to be written once this part of
  285 the code will be stable. <span style="background-color: #FF0000">TODO</span></p><h3><a name="Extension" id="Extension">Extension support</a></h3><p>There is a separate document explaining <a href="extensions.html">how the
  286 extension support works</a>.</p><h3><a name="Futher" id="Futher">Further reading</a></h3><p>Michael Kay wrote <a href="http://www-106.ibm.com/developerworks/library/x-xslt2/?dwzone=x?open&amp;l=132%2ct=gr%2c+p=saxon">a
  287 really interesting article on Saxon internals</a> and the work he did on
  288 performance issues. I wish I had read it before starting libxslt design (I
  289 would probably have avoided a few mistakes and progressed faster). A lot of
  290 the ideas in his papers should be implemented or at least tried in
  291 libxslt.</p><p>The <a href="http://xmlsoft.org/">libxml documentation</a>, especially <a href="http://xmlsoft.org/xmlio.html">the I/O interfaces</a> and the <a href="http://xmlsoft.org/xmlmem.html">memory management</a>.</p><h3><a name="TODOs" id="TODOs">TODOs</a></h3><p>redesign the XSLT stack frame handling. Far too much work is done at
  292 execution time. Similarly for the attribute value templates handling, at
  293 least the embedded subexpressions ought to be precompiled.</p><p>Allow output to be saved to a SAX like output (this notion of SAX like API
  294 for output should be added directly to libxml).</p><p>Implement and test some of the optimization explained by Michael Kay
  295 especially:</p><ul>
  296   <li>static slot allocation on the stack frame</li>
  297   <li>specific boolean interpretation of an XPath expression</li>
  298   <li>some of the sorting optimization</li>
  299   <li>Lazy evaluation of location path. (this may require more changes but
  300     sounds really interesting. XT does this too.)</li>
  301   <li>Optimization of an expression tree (This could be done as a completely
  302     independent module.)</li>
  303 </ul><p></p><p>Error reporting, there is a lot of case where the XSLT specification
  304 specify that a given construct is an error are not checked adequately by
  305 libxslt. Basically one should do a complete pass on the XSLT spec again and
  306 add all tests to the stylesheet compilation. Using the DTD provided in the
  307 appendix and making direct checks using the libxml validation API sounds a
  308 good idea too (though one should take care of not raising errors for
  309 elements/attributes in different namespaces).</p><p>Double check all the places where the stylesheet compiled form might be
  310 modified at run time (extra removal of blanks nodes, hint on the
  311 xsltCompMatch).</p><h3><a name="Thanks" id="Thanks">Thanks:</a></h3><p>Thanks to <a href="http://cmsmcq.com/">Michael Sperberg-McQueen</a> for
  312    various fixes and clarifications on this document!</p><p></p><p><a href="bugs.html">Daniel Veillard</a></p></td></tr></table></td></tr></table></td></tr></table></td></tr></table></td></tr></table></body></html>