Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>It seems as if I cant use an Xpath in the name attribute of the call-template element. How can I get around this?</p> </blockquote> <p>Good question, +1.</p> <p><strong>You can't. But you can use instead <code>&lt;xsl:apply-templates&gt;</code>.</strong></p> <p>Here is a quick demo:</p> <pre><code>&lt;xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:double="double" xmlns:incr="incr" xmlns:my="my:my" exclude-result-prefixes="double incr my" &gt; &lt;xsl:output method="text"/&gt; &lt;double:double/&gt; &lt;incr:incr/&gt; &lt;xsl:variable name="vFuncDouble" select="document('')/*/double:*[1]"/&gt; &lt;xsl:variable name="vFuncIncr" select="document('')/*/incr:*[1]"/&gt; &lt;xsl:function name="my:double"&gt; &lt;xsl:param name="arg1" /&gt; &lt;xsl:sequence select="2*$arg1"/&gt; &lt;/xsl:function&gt; &lt;xsl:function name="my:incr"&gt; &lt;xsl:param name="arg1" /&gt; &lt;xsl:sequence select="1+$arg1"/&gt; &lt;/xsl:function&gt; &lt;xsl:template name="double" match="double:*"&gt; &lt;xsl:param name="arg1"/&gt; &lt;xsl:sequence select="my:double($arg1)"/&gt; &lt;/xsl:template&gt; &lt;xsl:template name="incr" match="incr:*"&gt; &lt;xsl:param name="arg1"/&gt; &lt;xsl:sequence select="my:incr($arg1)"/&gt; &lt;/xsl:template&gt; &lt;xsl:function name="my:apply"&gt; &lt;xsl:param name="pFun" as="element()"/&gt; &lt;xsl:param name="arg1"/&gt; &lt;xsl:apply-templates select="$pFun"&gt; &lt;xsl:with-param name="arg1" select="$arg1"/&gt; &lt;/xsl:apply-templates&gt; &lt;/xsl:function&gt; &lt;xsl:template match="/"&gt; &lt;xsl:sequence select="my:apply($vFuncIncr, my:apply($vFuncDouble,2))"/&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>When this transformation is applied on any XML document (not used), the wanted result is produced:</strong></p> <pre><code>5 </code></pre> <p><strong>Do note</strong>: </p> <p><em>One can pass as parameter (the first argument) to <code>my:apply()</code> any "function" and</em> <code>my:apply()</code> <em>will apply it to its second argument</em>.</p> <p>Using this same principle <strong><a href="http://fxsl.sf.net" rel="nofollow">the FXSL library</a></strong> implemented Higher Order Functions (HOFs) in XSLT 1.0 and XSLT 2.0 -- <strong><a href="http://conferences.idealliance.org/extreme/html/2006/Novatchev01/EML2006Novatchev01.html" rel="nofollow">read more here</a></strong>.</p> <p>In the forthcoming <strong><a href="http://www.w3.org/TR/xpath-30/#id-literal-func-ref" rel="nofollow">XPath 3.0</a></strong> functions are for the first time first class objects in the <strong><a href="http://www.w3.org/TR/xpath-datamodel-30/#function-items" rel="nofollow">Xpath Data Model</a></strong> (XDM).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload