<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/xdmp.xsltInvoke.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>xdmp.xsltInvoke</api:function-name><api:suggest>xdmp.xsltinvoke</api:suggest><api:suggest>xdmp</api:suggest><api:suggest>xsltinvoke</api:suggest><api:function-link mode="xquery" fullname="xdmp:xslt-invoke">/apidoc/8.0/xdmp:xslt-invoke.xml</api:function-link><api:function mode="javascript" name="xsltInvoke" type="builtin" lib="xdmp" category="Extension" subcategory="XQuery Context" hidden="false" bucket="MarkLogic Built-In Functions" prefix="xdmp" namespace="http://marklogic.com/xdmp" fullname="xdmp.xsltInvoke"><api:summary>
   Executes an XSLT stylesheet against a node.
</api:summary><api:params><api:param name="path" type="xs:string"><api:param-description>
    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
    <em xmlns="http://www.w3.org/1999/xhtml">Application Developer's Guide</em>.
  </api:param-description><api:param-name>path</api:param-name><api:param-type>String</api:param-type></api:param><api:param name="input" type="node()?" optional="true"><api:param-description>
    The context node to which the stylesheet is applied.
  </api:param-description><api:param-name>input</api:param-name><api:param-type>Node?</api:param-type></api:param><api:param name="params" type="map:map?" optional="true"><api:param-description>
    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
    <a href="./xdmp:key-from-QName" xmlns="http://www.w3.org/1999/xhtml">xdmp:key-from-QName</a>
    is a convenient way to generate these keys.
    Each entry in the map is the value of the corresponding parameter.
  </api:param-description><api:param-name>params</api:param-name><api:param-type>Object?</api:param-type></api:param><api:param name="options" type="(element()|map:map)?" optional="true"><api:param-description>
  
  <span class="javascript" xmlns="http://www.w3.org/1999/xhtml">The options object. The default value is 
  null. </span>
  Additional options include:
  <dl xmlns="http://www.w3.org/1999/xhtml">
  
  <dt class="javascript"><p>mode</p></dt>
  <dd>A QName <span class="javascript"> (in clark notation) </span> specifying 
  the
  initial stylesheet mode to use (the <code>&lt;xsl:template&gt;</code> with 
  the specified <code>mode</code> attribute).</dd>
  
  <dt class="javascript"><p>template</p></dt>
  <dd>A QName <span class="javascript"> (in clark notation) </span> specifying 
  the name of the initial template to apply.</dd>
  
  <dt class="javascript"><p>encoding</p></dt>
  <dd>Specifies the encoding to use when reading the stylesheet into MarkLogic
  Server.  Supported values include <code>UTF-8</code>,
  <code>ISO-8859-1</code>, as well as many other popular encodings. 
  See the <em>Search Developer's Guide</em> 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
  <code>encoding</code> option will be matched to an encoding name according
  to the Unicode Charset Alias Matching rules
  (<a href="http://www.unicode.org/reports/tr22/#Charset_Alias_Matching">http://www.unicode.org/reports/tr22/#Charset_Alias_Matching</a>).
  An automatic encoding detector will be used if the value <code>auto</code>
  is specified.
  If no encoding can be detected, the encoding defaults to UTF-8.
  </dd>
  </dl>
  </api:param-description><api:param-name>options</api:param-name><api:param-type>Object?</api:param-type></api:param></api:params><api:return>ValueIterator</api:return><api:privilege>
<p xmlns="http://www.w3.org/1999/xhtml"><code>http://marklogic.com/xdmp/privileges/xslt-invoke</code></p>
</api:privilege><api:usage>
 <p xmlns="http://www.w3.org/1999/xhtml">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).</p>
</api:usage><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">

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

&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                  version="2.0"&gt;
    &lt;xsl:template match="/"&gt;
        &lt;xsl:text&gt;hello&lt;/xsl:text&gt;
    &lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;

xdmp.xsltInvoke("/hello.xsl", xdmp.unquote('&lt;foo/&gt;').next().value)
=&gt;
hello
</pre></api:example><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
//  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:

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

// 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.xsltInvoke("/params.xsl",
    xdmp.unquote('&lt;node&gt;Hello World&lt;/node&gt;').next().value,
    params);

=&gt;
&lt;?xml version="1.0" encoding="ASCII"?&gt;
&lt;output xmlns:f="foo" xmlns:b="bar"&gt;
  &lt;node&gt;Hello World&lt;/node&gt;
  &lt;greeting&gt;Hi there &lt;/greeting&gt;
  &lt;param&gt;Stephen&lt;/param&gt;
  &lt;param&gt;Ron&lt;/param&gt;
  &lt;param&gt;Dave&lt;/param&gt;
&lt;/output&gt;

</pre></api:example></api:function></api:function-page>