www.openlinksw.com
docs.openlinksw.com

Book Home

Contents
Preface

Virtuoso Functions Guide

Administration
Aggregate Functions
Array Manipulation
BPEL APIs
Backup
Compression
Cursor
Date & Time Manipulation
Debug
Dictionary Manipulation
Encoding & Decoding
File Manipulation
Free Text
Hashing / Cryptographic
LDAP
Locale
Mail
Miscellaneous
Number
RDF data
Remote SQL Data Source
Replication
SOAP
SQL
String
Transaction
Type Mapping
UDDI
User Defined Types & The CLR
Virtuoso Java PL API
Virtuoso Server Extension Interface (VSEI)
Web Server & Internet
XML
xmlagg
xmlattributes
xmladdattribute
xmlappendchildren
xmlconcat
xmlelement
xmlforest
xmlinsertafter
xmlinsertbefore
xmlreplace
xmltype.xmltype
xmltype.createnonsch...
xmltype.createschema...
xmltype.createxml
xmltype.existsnode
xmltype.extract
xmltype.getclobval
xmltype.getnamespace
xmltype.getnumval
xmltype.getrooteleme...
xmltype.getschemaurl
xmltype.getstringval
xmltype.isfragment
xmltype.isschemabase...
xmltype.isschemavali...
xmltype.isschemavali...
xmltype.schemavalida...
xmltype.setschemaval...
xmltype.toobject
xmltype.transform
xmlupdate
xper navigation
createxml
isentity
serialize_to_utf8_xm...
tidy_html
tidy_list_errors
updatexml
xml_add_system_path
xml_auto
xml_auto_dtd
xml_auto_schema
xml_create_tables_fr...
xml_cut
xml_doc_output_optio...
xml_get_system_paths
xml_load_mapping_sch...
xml_load_schema_decl
xml_namespace_scope
xml_persistent
xml_set_ns_decl
xml_template
xml_tree
xml_tree_doc
xml_tree_doc_media_t...
xml_uri_get
xml_validate_dtd
xml_validate_schema
xml_view_dtd
xml_view_schema
xmlsql_update
xpath_eval
xper_cut
xper_doc
xper_locate_words
xpf_extension
xpf_extension_remove
xquery_eval
xslt
xslt_format_number
xslt_sheet
xslt_stale
xte_head
xte_node
xte_node_from_nodebl...
xte_nodebld_acc
xte_nodebld_final
xte_nodebld_init
xtree_doc
XPATH & XQUERY

Functions Index

xslt

returns an XML document transformed by an XSLT stylesheet
xml_entity xslt (in sheet_uri varchar, in entity any, [in sheet_params vector]);
Description

This function takes the URI of a stylesheet and an XML entity and produces an XML entity representing the transformation result of the given entity with the given stylesheet. The result tree is separate from the argument tree and the only reference to it is the returned entity. Errors occurring in the transformation will be signalled as SQL states, with XML or XSLT specific conditions beginning with XS or XP.

The stylesheet can be passed parameters by specifying a third argument to xslt(). This will be a vector of name/value pairs. The values can be referenced from inside XPath expressions in the stylesheet. You may use any Virtuoso data type. The names in the parameter vector should appear without the '$' sign. If any of the parameter values is NULL the parameter will be ignored because NULL has no XPath counterpart. If the same name appears more than once in the vector, the last name/value pair is used and all preceding pairs with this name are silently ignored. Obviously, names should be strings that are valid XPath variable names.

xslt() applies the transformation in the sheet to the specified entity. The result is the root element of the result tree, an XML entity. This entity can be used as input to another transformation, can be serialized and sent to an HTTP client or stored, etc.

The URI of the sheet is used to locate the stylesheet. The protocol can be http, file or virt. Once the stylesheet has been retrieved it is cached and not refetched until the cache is invalidated with xslt_stale(). Included or imported style sheets will be fetched automatically, using the initial URI as base for any relative references. The sheet_uri is the URI of a stylesheet. This should be an absolute URI resolvable with xml_uri_get(). If the URI has previously been used as a stylesheet and has not been marked stale with xslt_stale(), Virtuoso will use the cached data instead of fetching and parsing the stylesheet resource.

When a resource with a .xsl extension is stored into the WebDAV, Virtuoso marks as stale any related cached resource. The URI for such stylesheets will be virt://WS.WS.SYS_DAV_RES.RES_FULL_PATH.RES_CONTENT:<path>. See the section about entity references in stored text for more on this type of URI. If the URI uses the file protocol, Virtuoso will compare the date of the file against the date of the cached stylesheet, automatically reloading the sheet if the file changes. This protocol is subject to the limitations on file system access imposed by the host operating system and the virtuoso.ini file system access control settings.

Parameters
sheet_uri – URI pointing to the location of an XSL stylesheet.
entity – parsed XML entity such as that returned by the xtree_doc() function
sheet_params – A vector of keyword/value parameters to be passed to the XSLT engine for use in the transformation.
Return Types

An XML entity resulting from transforming the given XML entity input with the given style sheet.

Examples
Basic Use
declare sheet, xml varchar;
declare xml_entity, myparams any;

sheet := 'virt://WS.WS.SYS_DAV_RES.RES_FULL_PATH.RES_CONTENT:/DAV/stylesheets/mysheet.xsl';
xml := 'virt://WS.WS.SYS_DAV_RES.RES_FULL_PATH.RES_CONTENT:/DAV/xmlsource/myxml.xml';
xml_entity := xtree_doc(xml);

myparams := vector('chapter', 'overview', 'imgroot', '/DAV/images/');

http_value(xslt(sheet, xml_entity, myparams));

This code will send the resultant transformation to the http stream. Note that the xml_entity must be a parsed XML entity such as that produced by xtree_doc.

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">

  <xsl:param name="chapter">default</xsl:param>
  <xsl:param name="imgroot"></xsl:param>

  <xsl:template match="/">
    <xsl:text>Value of chapter: </xsl:text><xsl:value-of select="$chapter" />
    <xsl:text>Value of imgroot: </xsl:text><xsl:value-of select="$imgroot" />
  </xsl:template>

</xsl:stylesheet>

This style sheet illustrates using parameters. Note how default values can be provided in the style sheet when the parameters are declared using the xsl:param tag.

See Also

xtree_doc()

xper_doc()

xml_tree_doc()

xml_tree()

xslt_stale()

XMLUpdate()