processXSLT — Applies stylesheet to given XML entity and returns the result.


entity processXSLT ( stylesheet_uri string ,
source entity ,
param1_name string ,
param1_value any ... ,
paramN_name string,
paramN_value any);


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 is applied to the value of source parameter. Obviously, source must be an entity. If source is not specified then the stylesheet is applied to the current entity.

Parameters can be passed to the stylesheet by specifying additional arguments to processXSLT() . The values can be referenced from inside XPath expressions in the stylesheet. The names of parameters should appear in argument list without the leading '$' sign. Unlike xslt() function, parameter can not be ignored depending on the type of its value. 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.

The function uses the cache of compiled stylesheets, see description of xslt() Virtuoso/PL function for more details.

For compatibility, the processXSLT() function can also be called as .



URI pointing to the location of an XSL stylesheet. It can be absolute or relative. A relative stylesheet_uri should be resolved before use, this requires base URI information. The base URI can be declared explicitly with the "__base_uri" parameter in XPATH or "declare base-uri" setter in XQuery. If not declared but the expression is a part of some stylesheet or XQuery module then the URI of module is used as a base URI. A run-time error is signalled if the URI is relative and the expression does not contain explicit declaration and the expression is neither in a stylesheet nor in a module.


XML entity that is the source of XSL transformation. If the function is called with only one argument then the context node is used as a source.


Name of parameter to be passed to the XSLT engine for use in the transformation.


Value of parameter with name specified by paramI_name .

Return Types

The function returns an XML entity that is the root entity of the resulting document of an XSL transformation.


Example24.612.XSLT inside XQuery expression

The query composes a single document that contain a list of labels for parcels. Depending on destination country and the state value of the parcel, the query applies one of three stylesheets that make a label from the address data; the query makes a label from every item of sequence $orders.

for $order in $orders let $customer := $customers/customer [ @CustId = $order/@CustId ] return
  if ($customer/address/@Country = "US")
    if ($order/sum >= 50.0)
      processXSLT ("file://registered-parcel.xsl", $customer/address, "value", $order/sum)
      processXSLT ("file://plain-parcel.xsl", $customer/address)
    processXSLT ("file://foreign-parcel.xsl", $customer/address, "value", $order/sum)