title: How can I pass HTML-element as parameter to XSLT function?
body: <p>I have the following XSLT-function that I use in a XSLT file to generate XHTML output:</p>
  
  <pre><code>&lt;xsl:function name="local:if-not-empty"&gt;
     &lt;xsl:param name="prefix"/&gt;
     &lt;xsl:param name="str"/&gt;
     &lt;xsl:param name="suffix"/&gt;
     &lt;xsl:if test="$str != ''"&gt;&lt;xsl:value-of select="concat($prefix, $str, $suffix)"/&gt;&lt;/xsl:if&gt;
  &lt;/xsl:function&gt;
  </code></pre>
  
  <p>it simply checks whether a string <code>str</code> is not empty and, if so, returns the string, concatenated with a prefix and a suffix.</p>
  
  <p>The function works fine as long as I only pass simple strings. But when I try to pass HTML elements as prefix or suffix, e.g.:</p>
  
  <pre><code>&lt;xsl:value-of select="local:if-not-empty('', /some/xpath/expression, '&lt;br/&gt;')"/&gt;
  </code></pre>
  
  <p>I get the following error message:</p>
  
  <pre><code>SXXP0003: Error reported by XML parser: The value of attribute "select"
  associated with an element type "null" must not contain the '&lt;' character.
  </code></pre>
  
  <p>The next thing I tried was to define a variable:</p>
  
  <pre><code>&lt;xsl:variable name="br"&gt;&lt;br/&gt;&lt;/xsl:variable&gt;
  </code></pre>
  
  <p>and pass it to the function:</p>
  
  <pre><code>&lt;xsl:value-of select="local:if-not-empty('', /some/xpath/expression, $br)"/&gt;
  </code></pre>
  
  <p>but here, of course, I get an empty string, as the value of the element is extracted, and not the element itself copied.</p>
  
  <p>My final hopeless attempt was to define a text element in the variable:</p>
  
  <pre><code>&lt;xsl:variable name="br"&gt;
     &lt;xsl:text disable-output-escaping="yes"&gt;&lt;br/&gt;&lt;/xsl:text&gt;
  &lt;/xsl:variable&gt;
  </code></pre>
  
  <p>and pass this to the function, but this wasn't permitted, either.</p>
  
  <pre><code>XTSE0010: xsl:text must not contain child elements
  </code></pre>
  
  <p>I probably don't understand the intricate inner workings of XSLT, but in my opinion adding a <code>&lt;br/&gt;</code> element within a XSLT-transformation through a generic function seems legitimate...</p>
  
  <p>Anyways... I'd appreciate if anyone could give me an alternative solution. I'd also like to understand why this doesn't work...</p>
  
  <p>PS: I'm using Saxon-HE 9.4.0.1J, Java version 1.6.0_24</p>