[xsl] linefeed to <br/> template

Subject: [xsl] linefeed to <br/> template
From: Flemming Jønsson <flj@xxxxxxxxxxxxx>
Date: Tue, 7 Oct 2003 17:10:00 +0200
I have som XML files from which I need to generate som HTML. 
Part of my XML is source code (or rather named queries in SQL) and I need to pretty-print these in some HTML tables.

I want to replace newlines with a <br/> - I found a template to do just that at www.skew.org/xml (Thanks Mark :)- but I have som problems I hope you can help me weed out. 

I use Xalan as XSLT processor, in case that changes anything.

Here is the template:

<xsl:template name="lf2br">
  <xsl:param name="StringToTransform"/>
    <xsl:when test="contains($StringToTransform,'&#10;')">
      <xsl:value-of select="substring-before($StringToTransform,'&#10;')"/>
      <xsl:call-template name="lf2br">
        <xsl:with-param name="StringToTransform" select="substring-after($StringToTransform,'&#10;')"/>
      <xsl:value-of select="$StringToTransform"/>

I want to use this call to remove newlines in a string - and store the result in a variable named sqlExample
<xsl:variable name="sqlExample">
  <xsl:call-template name="lf2br">
    <xsl:with-param name="StringToTransform" select="SQL/text()" />

This does not work, however. 
$sqlExample contains the text, but there are no <br> in it?

If I remove the <xsl:variable> surrounding the call-template part, it works just fine - the <br> tags are in the printed output as expected.
How come, it works when I print the output, but not when I store it in a variable?

I really would like to put the results in a variable, since I need to do some further processing on it - but is this not possible, without loosing the formatting?

Thank you for your help.

Flemming Joensson

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread