Loading TOC...


   $path as String,
   [$input as Node?],
   [$params as Object?],
   [$options as Object?]
) as ValueIterator


Executes an XSLT stylesheet against a node.

$path The path of the stylesheet to be executed. The path is resolved against the root of the App Server evaluating the query, the Modules directory, or relative to the calling module. For details on resolving paths, see "Importing XQuery Modules and Resolving Paths" in the Application Developer's Guide.
$input The context node to which the stylesheet is applied.
$params The stylesheet parameter values for this evaluation. Each key in the map is a string representing the name of the parameter in Clark notation: "{namespaceURI}localname". The function xdmp:key-from-QName is a convenient way to generate these keys. Each entry in the map is the value of the corresponding parameter.
$options The options object. The default value is null. Additional options include:


A QName (in clark notation) specifying the initial stylesheet mode to use (the <xsl:template> with the specified mode attribute).


A QName (in clark notation) specifying the name of the initial template to apply.


Specifies the encoding to use when reading the stylesheet into MarkLogic Server. Supported values include UTF-8, ISO-8859-1, as well as many other popular encodings. See the Search Developer's Guide for a list of character set encodings by language. All encodings will be translated into UTF-8 from the specified encoding. The string specifed for the encoding option will be matched to an encoding name according to the Unicode Charset Alias Matching rules (http://www.unicode.org/reports/tr22/#Charset_Alias_Matching). An automatic encoding detector will be used if the value auto is specified. If no encoding can be detected, the encoding defaults to UTF-8.

Required Privileges


Usage Notes

When running an XSLT stylesheet in MarkLogic, you pass in a node on which the stylesheet operates. Many stylesheets are written to expect the initial node to be a document node. In other XSLT processors, the node you pass to the stylesheet is typically read in from the filesystem and is always treated as a document node. In MarkLogic, you often get the node to pass to the stylesheet as the result of a query or a search, and the node is not necessarily a document node. Therefore, if your stylesheet expects the context node to be a document node, make sure to pass in a document node and not an element node. If you pass in an element node to a stylesheet that has default template rules to expect a document node, then you might miss the processing on the element you passed in (because the stylesheet might expect the child node to be the root element of the XML document, but if you passed in the root element instead of its parent document node, then the child nodes would be the children of the root element, causing the root element to miss its default processing).


// This example requires a document named hello.xsl directly
// at the App Server root with the following content:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    <xsl:template match="/">

xdmp.xsltInvoke("/hello.xsl", xdmp.unquote('<foo/>').next().value)


//  Hello World example for xslt:invoke, with a parameter.
//  Assumes a stylesheet named params.xsl directly at
//  the App Server root with the following content:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:f="foo" xmlns:b="bar"
    <xsl:param name="f:pName"/>
    <xsl:param name="b:bName"/>
    <xsl:param name="cName"/>
    <xsl:param name="greeting" select="'Hi there '"/>
    <xsl:template match="/">
         <xsl:copy-of select="node"/>
         <greeting><xsl:value-of select="$greeting"/></greeting>
         <param><xsl:value-of select="$f:pName"/></param>
         <param><xsl:value-of select="$b:bName"/></param>
         <param><xsl:value-of select="$cName"/></param>

// Run this against the above stylesheet:

var params = new Object();
var key1 = xdmp.keyFromQName(fn.QName("foo", "pName"));
params.key1 = "Stephen";
var key2 = xdmp.keyFromQName(fn.QName("bar", "bName"));
params.key2 = "Ron";
params.cName = "Dave";
    xdmp.unquote('<node>Hello World</node>').next().value,

<?xml version="1.0" encoding="ASCII"?>
<output xmlns:f="foo" xmlns:b="bar">
  <node>Hello World</node>
  <greeting>Hi there </greeting>


  • In the second example, with the parameters, the variables key1 and key2 are never used (a key with the *variable name* is added to the params object for each of them, but their *value* is never used). I guess the way to pass a param value with a namespace in its name is different, isn't it?
    • The values for key1 (f:pName) and key2 (b:bName) are used -- see the "<param><xsl:value-of select="$f:pName"/></param>" part of the XSL.
      • Thanks Dave, but no :-) I mean the value of the JavaScript variable "key1" (resp. "key2"), the QName itself. Those variables are never used. You can see "params.key1", but as far as I know, that does not use the variable "key1". The object params looks like the following, which does not know anything about the 2 QNames: { key1: "Stephen", key2: "Ron", cName: "Dave" }
        • Ah, I see your point. Looks like it should be <pre><code class="javascript">params[key1] = "Stephen";</code></pre>. That would give an object like this: <pre><code class="javascript">{ "{foo}pName": "Stephen", "key2": "Ron", "cName": "Dave" }</code></pre>
Powered by MarkLogic Server 7.0-4.1 and rundmc | Terms of Use | Privacy Policy