Note that there are some explanatory texts on larger screens.

plurals
  1. POWhere do I put an XSL function in an XSL document?
    text
    copied!<p>I have an XSL style sheet for which I need to add some custom string manipulation using an xsl:function. But I am having trouble trying to work out where to put the function in my document.</p> <p>My XSL simplified looks like this,</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;xsl:stylesheet version="1.0" xmlns:my="myFunctions" xmlns:d7p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:import href="Master.xslt"/&gt; &lt;xsl:template match="/"&gt; &lt;fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"&gt; &lt;!-- starts actual layout --&gt; &lt;fo:page-sequence master-reference="first"&gt; &lt;fo:flow flow-name="xsl-region-body"&gt; &lt;!-- this defines a title level 1--&gt; &lt;fo:block xsl:use-attribute-sets="heading"&gt; HelloWorld &lt;/fo:block&gt; &lt;/fo:flow&gt; &lt;/fo:page-sequence&gt; &lt;/fo:root&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>And I want to put in a simple function, say,</p> <pre><code> &lt;xsl:function name="my:helloWorld"&gt; &lt;xsl:text&gt;Hello World!&lt;/xsl:text&gt; &lt;/xsl:function&gt; </code></pre> <p>But I cannot work out where to put the function, when I put it under the node I get an error saying '<em>xsl:function' cannot be a child of the 'xsl:stylesheet' element.</em>, and if I put it under the node I get a similar error.</p> <p>Where should I put the function? Idealy I would like to put my functions in an external file and import them into my xsl files.</p>
 

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