Sophie

Sophie

distrib > Fedora > 14 > x86_64 > media > updates > by-pkgid > 71d40963b505df4524269198e237b3e3 > files > 1094

virtuoso-opensource-doc-6.1.4-2.fc14.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
 <head profile="http://internetalchemy.org/2003/02/profile">
  <link rel="foaf" type="application/rdf+xml" title="FOAF" href="http://www.openlinksw.com/dataspace/uda/about.rdf" />
  <link rel="schema.dc" href="http://purl.org/dc/elements/1.1/" />
  <meta name="dc.title" content="13. XML Support" />
  <meta name="dc.subject" content="13. XML Support" />
  <meta name="dc.creator" content="OpenLink Software Documentation Team ;&#10;" />
  <meta name="dc.copyright" content="OpenLink Software, 1999 - 2009" />
  <link rel="top" href="index.html" title="OpenLink Virtuoso Universal Server: Documentation" />
  <link rel="search" href="/doc/adv_search.vspx" title="Search OpenLink Virtuoso Universal Server: Documentation" />
  <link rel="parent" href="webandxml.html" title="Chapter Contents" />
  <link rel="prev" href="xq.html" title="XQuery 1.0 Support" />
  <link rel="next" href="xmltype.html" title="XMLType" />
  <link rel="shortcut icon" href="../images/misc/favicon.ico" type="image/x-icon" />
  <link rel="stylesheet" type="text/css" href="doc.css" />
  <link rel="stylesheet" type="text/css" href="/doc/translation.css" />
  <title>13. XML Support</title>
  <meta http-equiv="Content-Type" content="text/xhtml; charset=UTF-8" />
  <meta name="author" content="OpenLink Software Documentation Team ;&#10;" />
  <meta name="copyright" content="OpenLink Software, 1999 - 2009" />
  <meta name="keywords" content="" />
  <meta name="GENERATOR" content="OpenLink XSLT Team" />
 </head>
 <body>
  <div id="header">
    <a name="xslttrans" />
    <img src="../images/misc/logo.jpg" alt="" />
    <h1>13. XML Support</h1>
  </div>
  <div id="navbartop">
   <div>
      <a class="link" href="webandxml.html">Chapter Contents</a> | <a class="link" href="xq.html" title="XQuery 1.0 Support">Prev</a> | <a class="link" href="xmltype.html" title="XMLType">Next</a>
   </div>
  </div>
  <div id="currenttoc">
   <form method="post" action="/doc/adv_search.vspx">
    <div class="search">Keyword Search: <br />
        <input type="text" name="q" /> <input type="submit" name="go" value="Go" />
    </div>
   </form>
   <div>
      <a href="http://www.openlinksw.com/">www.openlinksw.com</a>
   </div>
   <div>
      <a href="http://docs.openlinksw.com/">docs.openlinksw.com</a>
   </div>
    <br />
   <div>
      <a href="index.html">Book Home</a>
   </div>
    <br />
   <div>
      <a href="contents.html">Contents</a>
   </div>
   <div>
      <a href="preface.html">Preface</a>
   </div>
    <br />
   <div class="selected">
      <a href="webandxml.html">XML Support</a>
   </div>
    <br />
   <div>
      <a href="forxmlforsql.html">Rendering SQL Queries as XML (FOR XML Clause)</a>
   </div>
   <div>
      <a href="composingxmlinsql.html">XML Composing Functions in SQL Statements (SQLX)</a>
   </div>
   <div>
      <a href="xmlservices.html">Virtuoso XML Services</a>
   </div>
   <div>
      <a href="queryingxmldata.html">Querying Stored XML Data</a>
   </div>
   <div>
      <a href="updategrams.html">Using UpdateGrams to Modify Data</a>
   </div>
   <div>
      <a href="xmltemplates.html">XML Templates</a>
   </div>
   <div>
      <a href="xmlschema.html">XML DTD and XML Schemas</a>
   </div>
   <div>
      <a href="xq.html">XQuery 1.0 Support</a>
   </div>
   <div class="selected">
      <a href="xslttrans.html">XSLT Transformation</a>
    <div>
        <a href="#namespaces" title="Namespaces ">Namespaces </a>
        <a href="#xsloutputelt" title="The &lt;xsl:output&gt; Tag">The &lt;xsl:output&gt; Tag</a>
        <a href="#xsltextparams" title="External Parameters in XSLT Stylesheets">External Parameters in XSLT Stylesheets</a>
        <a href="#xsltfunctions" title="Functions">Functions</a>
        <a href="#xsltexamples" title="XSLT Examples">XSLT Examples</a>
        <a href="#userdefxpathfunc4xsl" title="XPath Function Extensions for XSLT">XPath Function Extensions for XSLT</a>
        <a href="#xsltsupport" title="Status Of XSLT And XPath Implementation">Status Of XSLT And XPath Implementation</a>
    </div>
   </div>
   <div>
      <a href="xmltype.html">XMLType</a>
   </div>
   <div>
      <a href="xmldom.html">Changing XML entities in DOM style</a>
   </div>
    <br />
  </div>
  <div id="text">
<a name="xslttrans" />
    <h2>13.9. XSLT Transformation</h2>

<p>
Virtuoso implements XSLT 1.0 transformations as SQL callable
functions.  In general, Virtuoso&#39;s XSLT processor follows the XSLT 1.0
standard as far as possible without loss of database-related
functionality.  The most important difference is in error handling.
While XSLT rules assume that almost any error must be recovered,
Virtuoso will stop the transformation in case of data access error or
in case of serious arithmetic error, such as divide by zero.  This is
due to the greater complexity of the Virtuoso XSLT processor&#39;s
environment.  Standalone processors generally accept a set of files as
input parameters, the only output is the resulting transformation as a
file, and all configuration parameters are listed on the command line.
Virtuoso&#39;s XSLT processor may retrieve both data and stylesheets from
local filesystems, local tables, remote datasources, or the Web.
Parameters of the stylesheet transformation may be prepared by
complicated Virtuoso PL procedures and so on.  Plain XSLT processors may
continue producing &quot;dirty&quot; output; Virtuoso&#39;s processor will
stop upon encountering serious in order to produce helpful error
diagnostics.
    </p>
    <p>
Another important difference is that Virtuoso has one processor for
XSLT, XPath and XQuery. The user will find this convenient because an
application may use XSLT-specific functions in XPath expressions,
XQuery functions in XSLT, and so on.  If extension functions are
defined for the XSLT processor, they may also be used in XPath and
XQuery expressions without any additional operations.  One caveat is
that this may invalidate some rules related to the document order of
nodes in node-sets.  Both the XPath 1.0 and XSLT 1.0 standards say
that some functions must process the node that is first in document
order from a given node-set.  In such cases Virtuoso&#39;s processor will
process the first node found in the node-set, regardless of whether it
is actually the first in document order or not.  This is done because
the old XPath rule is nonsensical if nodes of the node-set are
retrieved from more than one document or are created in the query.
The processor follows the old rule for 99% of real expressions.
Specifically, it fully matches the standards&#39; rules for all XPath
expressions that are free of reverse-order axes and non-standard
functions.
    </p>


<a name="namespaces" />
    <h3>13.9.1. Namespaces </h3>

	<p>
In the following the <span class="computeroutput">xsl:</span> namespace
prefix is used to mean
&quot;http://www.w3.org/XSL/Transform/1.0&quot;.  In fact all
namespace URI&#39;s beginning with
&quot;http://www.w3.org/XSL/Transform&quot; are considered as the
XSLT namespace.  The namespaces
&quot;http://www.w3.org/1999/XSL/Transform&quot; and
&quot;http://www.w3.org/TR/WD-xsl&quot; are recognized as synonymous.
No other namespace URI&#39;s have special significance.
</p>
<br />


<a name="xsloutputelt" />
    <h3>13.9.2. The &lt;xsl:output&gt; Tag</h3>
	<p>
The Virtuoso XSLT processor recognizes and verifies the
<span class="computeroutput">&lt;xsl:output&gt;</span> tag.  The only
<span class="computeroutput">&lt;xsl:output&gt;</span> attributes that are used are
the
<span class="computeroutput">method</span>,
<span class="computeroutput">encoding</span>,
<span class="computeroutput">omit-xml-declaration</span>,
<span class="computeroutput">media-type</span>,
<span class="computeroutput">doctype-public</span>
<span class="computeroutput">doctype-system</span>
and
<span class="computeroutput">indent</span>.
The processor output is created
in the character set that is in effect for the client or the one
specified by encoding.
</p>
<p>
The SQL function <a href="fn_xml_tree_doc_media_type.html">
xml_tree_doc_media_type()</a>
returns the media type in effect for the result of the <a href="fn_xslt.html">xslt()</a> function based on
the xsl:output <span class="computeroutput">media-type</span> and
<span class="computeroutput">method</span> attributes of the stylesheet applied.
This method is also used for producing FOR XML AUTO WebDAV resources
for HTTP reply generation.
</p>
<br />
  
    <a name="xsltextparams" />
    <h3>13.9.3. External Parameters in XSLT Stylesheets</h3>
    <p>
The XSLT 1.0 standard specifies that parameters may be passed to the
XSLT processor from its environment in order to control data
transformation, but the details are implementation-specific.
Virtuoso&#39;s XSLT Processor will accept default values for global
parameters from the optional third argument of the <a href="fn_xslt.html">xslt()</a> Virtuoso PL function.  This argument, if
specified, must be a vector of parameter names and values of the form
<span class="computeroutput">vector(name1, value1,... nameN,
valueN)</span>, where <span class="computeroutput">name1 ... nameN</span>
must be of type <span class="computeroutput">varchar</span>, and <span class="computeroutput">value1
... valueN</span> may be of any Virtuoso datatype, but may not be
null.  If a parameter has a null value specified, it is removed from
the vector without any further processing.  After removal of null
values, duplicate names are eliminated.  If a name occurs more than
once in the vector, only the last one will be retained.
    </p>
    <p>
When the XSLT Processor begins the transformation of the document, it
creates two stacks of variables, one for global variables and one for
local variables.  Initially the stacks are empty.
Then it prepares temporary indexes for all
<span class="computeroutput">&lt;xsl:key&gt;</span> elements; all future calls
of <a href="xpf_key.html">key()</a> function
will return without any searches through the source document.
Only after the processing of all keys of the stylesheet, the
XSLT Processor pushes all
parameters from the third argument of
the <a href="fn_xslt.html">xslt()</a> function
into the stack of local variables.
Then, as described in the XSLT specification, it
initializes top-level variables and parameters.  For every
<span class="computeroutput">&lt;xsl:variable&gt;</span> or
<span class="computeroutput">&lt;xsl:param&gt;</span> element found at the
top-level of the main stylesheet or at the top level of some imported
stylesheet, the processor calculates the value and pushes the created
variable into the stack of local variables.  The
<span class="computeroutput">&lt;xsl:param&gt;</span> element is ignored if the
specified name is already declared in the vector of parameters or in
some stylesheet imported before.  When all top-level variables and
parameters are initialized, the content of the stack of local
variables is moved into the stack of global variables, and the stack
of local variables is made empty.  During the rest of the XSLT
transformation, these variables will be used as global variables. They
may be temporarily shadowed by inner declarations of local variables
- though not by declarations of local parameters - but they
cannot be changed.
Note that expressions for values of variables and parameters may contain
calls of <a href="xpf_key.html">key()</a> function,
because temporary indexes are ready to use before the first such
expression is calculated. Expressions of
<span class="computeroutput">&lt;xsl:key&gt;</span> elements may not refer to any
parameters or variables, due to the same reason.
    </p>
  <br />


<a name="xsltfunctions" />
    <h3>13.9.4. Functions</h3>
<p>
The <a href="fn_xslt.html">xslt()</a>
Virtuoso/PL function applies a given stylesheet to a given source XML
document and returns the transformed document.  There is no restriction to
what a VSP page can output, this is usually HTML but can be XML.  The function
<a href="fn_http_xslt.html">http_xslt()</a> allows
a stylesheet to be applied to a whole output of an VSP page before it is sent
to the user agent.
Functions
<a href="fn_xslt_sheet.html">xslt_sheet()</a>
and
<a href="fn_xslt_stale.html">xslt_stale()</a>
allow you to create and destroy a stylesheet dynamically.
Function <a href="">xmlupdate()</a>
is convenient for very simple &quot;search-and replace&quot; transformations.
</p>
<br />


<a name="xsltexamples" />
    <h3>13.9.5. XSLT Examples</h3>
	<p>
This section covers some examples of applying XSLT to various stored data.
</p>

<a name="" />
    <div class="example">
<div>
        <pre class="programlisting">
create procedure xml_view_string (in _view varchar)
{
  declare _body any;
  declare _pf varchar;
  _body := string_output ();
  http (&#39;&lt;document&gt;&#39;, _body);
  _pf := concat (&#39;DB.DBA.http_view_&#39;, _view);
  call (_pf) (_body);
  http (&#39;&lt;/document&gt;&#39;, _body);

  return (string_output_string (_body));
}
</pre>
      </div>

<div>
        <pre class="programlisting">
create procedure xslt_view (in v varchar, in xst varchar)
{

  declare str, r varchar;
  xslt_sheet (xst, xtree_doc (file_to_string (xst)));
  str := xml_view_string (v);
  r := xslt (xst, xtree_doc (str));
  declare str_out any;
  str_out := string_output ();
  http_value (r, 0, str_out);
  string_to_file (&#39;xslt.out&#39;, string_output_string (str_out), 0);
}
</pre>
      </div>
</div>
	<p>
These functions will take the serialized text of an XML view created
with CREATE XML VIEW, transform it with a stylesheet and store the
result into a file.
</p>
	<p>
The first function returns a string containing the text generated as
the value of the XML view specified as argument.  It calls the
serialization function, which is <span class="computeroutput">DB.DBA.http_view_ +
view name</span>.  This function writes the text into the
string output stream passed to it.  Note that the function wraps the
text inside a <span class="computeroutput">&lt;document&gt;</span> element in order
to make it well-formed, since the view serialization function will
emit multiple top-level elements, one for each selected row in the
root table in the XML view.
</p>
	<p>
The <span class="computeroutput">xslt_view()</span> function first defines the style
sheet, which it takes from a file in this case.  The
<span class="computeroutput">xslt_sheet()</span> function is called with the name and
root element of the parsed file.
</p>
	<p>
The function next gets the string to process, parses it as XML, and
converts the parse tree into an entity object.  This is then passed to
the <span class="computeroutput">xslt()</span> function.  The result is another
entity object.  This is finally serialized as XML text and written
into the file <span class="computeroutput">xslt.out</span>.
</p>
	<p>
These examples show how to parse and serialize XML using varchars,
string output streams and the entity data type.
</p>
	<p>
The central points are:
</p>
<ul>
      <li>
The XML entity object is a reference to a particular element of a
parsed XML document, The underlying document is only visible through
this reference.  A string is converted into such a document and a
reference to the document&#39;s root is returned by the
<div>
          <pre class="programlisting">xtree_doc (string)</pre>
        </div> function.
In previous versions of Virtuoso, the combination
<div>
          <pre class="programlisting">xml_tree_doc (xml_tree (string))</pre>
        </div>
was used for this purpose; this combination still works to
maintain backwards compatibility, but using xtree_doc() is preferable.
</li>
      <li>
A string output is used to capture the serialization of data by the
http_value() function.  If the string output were
not specified the data would be sent to the HTTP client directly, if
we were running in an HTTP request context.
</li>
    </ul>
<br />

<a name="userdefxpathfunc4xsl" />
    <h3>13.9.6. XPath Function Extensions for XSLT</h3>
<p>Virtuoso provides a way to extend the abilities of the XSLT
processor by creating user defined XPath functions.  The functions
<a href="fn_xpf_extension.html">xpf_extension()</a> and
<a href="fn_xpf_extension_remove.html">xpf_extension_remove()</a>
allow addition and removal of XPath extension functions.</p>

<br />

<a name="xsltsupport" />
    <h3>13.9.7. Status Of XSLT And XPath Implementation</h3>
<p>Items marked with (*) are currently not implemented.</p>


<a name="xpathaxissupport" />
    <h4>13.9.7.1. XPath Axes</h4>
<ul>
      <li>ancestor::</li>
      <li>ancestor-or-self::</li>
      <li>attribute::</li>
      <li>child::</li>
      <li>descendant::</li>
      <li>descendant-or-self::</li>
      <li>following::</li>
      <li>following-sibling::</li>
      <li>namespace:: (*)</li>
      <li>parent::</li>
      <li>preceding::</li>
      <li>preceding-sibling::</li>
      <li>self::</li>
    </ul>
<br />


<a name="xpathnodefunctions" />
    <h4>13.9.7.2. Node Functions</h4>
<ul>
      <li>number <a href="xpf_position.html">position</a>()</li>
      <li>number <a href="xpf_count.html">count</a>(node-set)</li>
      <li>string <a href="xpf_local_name.html">local-name</a>(node-set?)</li>
      <li>string <a href="xpf_namespace_uri.html">namespace-uri</a>(node-set?)</li>
      <li>string <a href="xpf_name.html">name</a>(node-set?)</li>
      <li>boolean <a href="xpf_lang.html">lang</a>(string)</li>
    </ul>
<br />


<a name="xpathnodesetfunctions" />
    <h4>13.9.7.3. Node Set Functions</h4>
<ul>
      <li>node-set <a href="xpf_document.html">document</a>(string, string?, integer?, name?, name?, string?)</li>
      <li>node-set <a href="xpf_document_literal.html">document-literal</a>(string, string?, integer?, name?, name?, string?)</li>
      <li>node-set <a href="xpf_id.html">id</a>(object)</li>
      <li>node-set <a href="xpf_append.html">append</a>(object, object, ..., object)</li>
    </ul>
<br />


<a name="xpathstringfunctions" />
    <h4>13.9.7.4. String Functions</h4>
<ul>
      <li>string <a href="xpf_string.html">string</a>(object?)</li>
      <li>string <a href="xpf_serialize.html">serialize</a>(object?)</li>
      <li>string <a href="xpf_format_number.html">format-number</a>(number, string, string?)</li>
      <li>string <a href="xpf_concat.html">concat</a>(object, object, ..., object)</li>
      <li>number <a href="xpf_string_length.html">string-length</a>(string?)</li>
      <li>boolean <a href="xpf_contains.html">contains</a>(string, string)</li>
      <li>boolean <a href="xpf_text_contains.html">text-contains</a>(string, string)</li>
      <li>boolean <a href="xpf_starts_with.html">starts-with</a>(string, string)</li>
      <li>boolean <a href="xpf_ends_with.html">ends-with</a>(string, string)</li>
      <li>string <a href="xpf_substring.html">substring</a>(string, number, number?)</li>
      <li>string <a href="xpf_substring_before.html">substring-before</a>(string, string)</li>
      <li>string <a href="xpf_substring_after.html">substring-after</a>(string, string)</li>
      <li>string <a href="xpf_normalize_space.html">normalize-space</a>(string?)</li>
      <li>string <a href="xpf_translate.html">translate</a>(string, string, string)</li>
      <li>string <a href="xpf_replace.html">replace</a>(string, string, string)</li>
    </ul>
<br />


<a name="xpathboolfunctions" />
    <h4>13.9.7.5. Boolean Functions</h4>
<ul>
      <li>boolean <a href="xpf_boolean.html">boolean</a>(object)</li>
      <li>boolean <a href="xpf_true.html">true</a>()</li>
      <li>boolean <a href="xpf_false.html">false</a>()</li>
      <li>boolean <a href="xpf_not.html">not</a>(boolean)</li>
      <li>boolean <a href="xpf_and.html">and</a>(boolean, boolean, ..., boolean)</li>
      <li>boolean <a href="xpf_or.html">or</a>(boolean, boolean, ..., boolean)</li>
      <li>boolean <a href="xpf_some.html">some</a>(name, boolean, node-set)</li>
      <li>boolean <a href="xpf_every.html">every</a>(name, boolean, node-set)</li>
      <li>boolean <a href="xpf_function_available.html">function_available</a>(name)</li>
    </ul>
<br />


<a name="xpathnumberfunctions" />
    <h4>13.9.7.6. Number Functions</h4>
<ul>
      <li>number <a href="xpf_number.html">number</a>(object?)</li>
      <li>number <a href="xpf_floor.html">floor</a>(number)</li>
      <li>number <a href="xpf_ceiling.html">ceiling</a>(number)</li>
      <li>number <a href="xpf_round.html">round</a>(number)</li>
      <li>number <a href="xpf_sum.html">sum</a>(number)</li>
      <li>number <a href="xpf_avg.html">avg</a>(number)</li>
      <li>number <a href="xpf_max.html">max</a>(number)</li>
      <li>number <a href="xpf_min.html">min</a>(number)</li>
    </ul>
<br />


<a name="xpathnumberfunctions" />
    <h4>13.9.7.7. XSLT-specific Functions</h4>
<ul>
      <li>
        <a href="xpf_current.html">current</a>()</li>
      <li>
        <a href="xpf_function_available.html">function-available</a>(string)</li>
      <li>
        <a href="xpf_unparsed_entity_uri.html">unparsed-entity-uri</a>(string)</li>
      <li>
        <a href="xpf_system_property.html">system-property</a>(string)</li>
    </ul>
<br />


<a name="xslt_keys" />
    <h4>13.9.7.8. XSLT 1.0 Elements and Attributes</h4>
<ul>
      <li>xsl:apply-imports</li>
      <li>xsl:apply-templates</li>
      <li>xsl:attribute</li>
      <li>xsl:attribute-set (*)</li>
      <li>xsl:call-template</li>
      <li>xsl:choose</li>
      <li>xsl:comment</li>
      <li>xsl:copy</li>
      <li>xsl:copy-of</li>
      <li>xsl:decimal-format</li>
      <li>xsl:element</li>
      <li>xsl:fallback (*)</li>
      <li>xsl:for-each</li>
      <li>xsl:if</li>
      <li>xsl:import</li>
      <li>xsl:include</li>
      <li>xsl:key</li>
      <li>xsl:message</li>
      <li>xsl:namespace-alias</li>
      <li>xsl:number 		NOTE: formatting and level=&quot;any&quot; is not implemented</li>
      <li>xsl:otherwise</li>
      <li>xsl:output</li>
      <li>xsl:param</li>
      <li>xsl:preserve-space (*)</li>
      <li>xsl:processing-instruction</li>
      <li>xsl:sort</li>
      <li>xsl:strip-space</li>
      <li>xsl:stylesheet</li>
      <li>xsl:template</li>
      <li>xsl:text</li>
      <li>xsl:transform (*) NOTE: use xsl:stylesheet instead</li>
      <li>xsl:value-of</li>
      <li>xsl:variable</li>
      <li>xsl:when</li>
      <li>xsl:with-param</li>
    </ul>
<br />
<br />
<table border="0" width="90%" id="navbarbottom">
    <tr>
        <td align="left" width="33%">
          <a href="xq.html" title="XQuery 1.0 Support">Previous</a>
          <br />XQuery 1.0 Support</td>
     <td align="center" width="34%">
          <a href="webandxml.html">Chapter Contents</a>
     </td>
        <td align="right" width="33%">
          <a href="xmltype.html" title="XMLType">Next</a>
          <br />XMLType</td>
    </tr>
    </table>
  </div>
  <div id="footer">
    <div>Copyright© 1999 - 2009 OpenLink Software All rights reserved.</div>
   <div id="validation">
    <a href="http://validator.w3.org/check/referer">
        <img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" />
    </a>
    <a href="http://jigsaw.w3.org/css-validator/">
        <img src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!" height="31" width="88" />
    </a>
   </div>
  </div>
 </body>
</html>