The format of an XML template is shown below, illustrating how SQL queries and updategrams are specified:

<root xmlns:sql="urn:schemas-openlink-com:xml-sql" sql:xsl='xslt url' >
    <sql:param name=":...">..</sql:param>
    <sql:param name=":...">..</sql:param>...
    select ... for xml ..
    Update gramm

The root element can contain two attributes. The first is the required namespace declaration of xmlns:sql="urn:schemas-openlink-com:xml-sql", required to identify the XML as an XML template. The second attribute allows the specification of an optional XSLT stylesheet to be applied to the resulting XML document, if applicable. The XSLT stylesheet file can be specified as either a relative or absolute URL.

The following elements can be defined in the "sql" namespace for an XML Template:

  • The


    tag can be any name, its purpose is to provide the top-level element required for any well-formed XML, and provides the root element for the resulting XML document, if any.

  • <sql:header>

    This tag is used to hold the parameters for templates execution such as <sql:param> elements. The <sql:header> element allow us to define multiple parameters.

  • <sql:param>

    This element is used to define a named parameter that is passed to the query and/or updategram inside the template. Each <xsl:param> element defines one parameter. Multiple <xsl:param> elements can be specified within the <sql:header> element.

  • <sql:query>

    This element is used to specify SQL/XML queries. It is possible to specify multiple <sql:query> elements within a single template.

  • <sql:sync>

    This element is used to contain updategrams.

<sql:query> and <sql:sync> entries are executed sequentially in the order they appear as separate transactions. Therefore, if you have multiple <sql:query> or <sql:sync> elements in the template, if one fails, the others will proceed.

XML templates can be executed directly from Virtuoso PL using the xml_template() function.

To allow XML template execution from a Virtuoso virtual directory and it's descendants the special option: 'xml_templates' must be used in the virtual directory definition. This option can be set from the Conductor / Web Application Server / Virtual Domains & Directories or from SQL (or ISQL) using the vhost_define(.... , opts=>vector('xml_templates', 'yes')); function. In the usual way, the SQL user specified for VSP execution within the virtual directory definition will be used for executing the templates within such web directories. If your XML Templates are to run from a DAV directory then you must allow suitable execute permissions for the file and directory.

When a virtual directory is configured to allow execution of XML templates be aware that this also means that descendant directories inherit this property. Also be aware that this also allows execution of VSP files in the normal way. WebDAV also has another layer of security attributes that will need to be set to enable files to be executable. By default files in DAV do not have execute privileges.

Explicitly specifying "contenttype=text/html" as a URL parameter will instruct the Virtuoso HTTP server to return the HTML output.