Re: [xsl] xsl:variables

Subject: Re: [xsl] xsl:variables
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Sat, 19 May 2001 09:10:03 +0100
Hi Joerg,

> Why doesn't the escaping of special characters work any longer if I
> store the stuff in an xsl:variable? Or how can I solve the problem?

Disabling output escaping is supposed to be used to create non-XML
output.  When you create a text node (using xsl:text or xsl:value-of)
and you set the variable disable-output-escaping="yes" then the
processor attaches some kind of flag to that text node to indicate
that it shouldn't use output escaping when it serialises it to a file.

Now, when you set a variable to a result tree fragment (i.e. you use
its content) then you're actually setting it to a little tree. So with
the samples you gave, the tree has this text node in it. When you use
xsl:value-of to get the value of the result tree fragment, you're
asking the processor to convert this into a string.  This is actually
an error (see http://www.w3.org/TR/xslt#disable-output-escaping) and
if the processor recovers from it, then it has to ignore the disable
output escaping.

You could try *copying* the content of the variable instead, as that
way you'll be getting a copy of the text node that it holds, which may
mean that the disable-output-escaping flag is still there.  However,
as with all uses of disabling output escaping, you should only be
using this if there's absolutely no alternative.  In your third
example at least, it's very unclear why you're doing:

    <xsl:variable name="display2">
      <xsl:text disable-output-escaping="yes">
        <![CDATA[
          <div align="center">
            <img src="http://www.mulberrytech.com/image/sberry2.gif"/>
          </div>
        ]]>
      </xsl:text>
    </xsl:variable>
    <xsl:value-of select="$display2"/>

When the content of the variable is well-formed XML (or would be if
you didn't escape it using a CDATA section). I think you want to do:

  <xsl:variable name="display2">
     <div align="center">
        <img src="http://www.mulberrytech.com/image/sberry2.gif"; />
     </div>
  </xsl:variable>
  <xsl:copy-of select="$display2" />

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



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


Current Thread