Discussion:
XSLT Disable-Output-Escaping Not Working
Shelli D. Orton
2004-05-13 16:29:13 UTC
Permalink
Hi,

I'm fairly new to XLST and have come across this problem. I have a template
that creates an image element as below:

<xsl:element name="img">
<xsl:attribute name="src">
<xsl:choose>
<xsl:when test="Content/Title/image">
<xsl:value-of select="Content/Title/image" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$defaultImage"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:attribute name="alt">
<xsl:value-of select="MetaData/title" disable-output-escaping="yes"/>
</xsl:attribute>
</xsl:element>

When the value of MetaData/title is "This &amp; That", the &amp; is escaped
resulting in a title of "This &amp;amp; That" which the browser displays as
"This &amp; That". Shouldn't the result be "This &amp; That" which the
browser displays as "This & That"? I have used the disable-output-escaping
attribute in many other places and it has always worked before.


Thanks for any help.

Shelli
Michael Kay
2004-05-13 16:36:57 UTC
Permalink
Don't use disable-output-escaping if you don't understand it. It's a way of
generating invalid XML or HTML for use in the rare occasions where that's
what you need to do. It's doing just that here, which means it IS working,
and isn't what you want.

Michael Kay
-----Original Message-----
Sent: 13 May 2004 16:29
To: XSL List
Subject: [xsl] XSLT Disable-Output-Escaping Not Working
Hi,
I'm fairly new to XLST and have come across this problem. I
have a template
<xsl:element name="img">
<xsl:attribute name="src">
<xsl:choose>
<xsl:when test="Content/Title/image">
<xsl:value-of
select="Content/Title/image" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of
select="$defaultImage"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:attribute name="alt">
<xsl:value-of select="MetaData/title"
disable-output-escaping="yes"/>
</xsl:attribute>
</xsl:element>
When the value of MetaData/title is "This &amp; That", the
&amp; is escaped
resulting in a title of "This &amp;amp; That" which the
browser displays as
"This &amp; That". Shouldn't the result be "This &amp; That"
which the
browser displays as "This & That"? I have used the
disable-output-escaping
attribute in many other places and it has always worked before.
Thanks for any help.
Shelli
--+------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
--+--
David Carlisle
2004-05-13 16:38:31 UTC
Permalink
I'm fairly new to XSLT
In that case you really don't want to use disable-output-esacping it is
only for very special and strange circumstances, and it's an optional
feature, an XSLT processor is allowed to just ignore it.

Even when it is supported by the processor the XSLT spec specifies that
it has no effect on attribute values, which is where you are using it.

If you did succeed in generating an unescaped & your output would be
illegal HTML or XML, so why would you want that?

David
--
The LaTeX Companion
http://www.awprofessional.com/bookstore/product.asp?isbn=0201362996
http://www.amazon.co.uk/exec/obidos/tg/detail/-/0201362996/202-7257897-0619804


________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________
Shelli D. Orton
2004-05-13 17:07:07 UTC
Permalink
I guess the complication in this case is that I'm not generating HTML or
XML, but WML which has different character escaping requirements.

Thanks anyway,
Shelli
-----Original Message-----
Sent: Thursday, May 13, 2004 10:39 AM
Subject: Re: [xsl] XSLT Disable-Output-Escaping Not Working
I'm fairly new to XSLT
In that case you really don't want to use disable-output-esacping it is
only for very special and strange circumstances, and it's an optional
feature, an XSLT processor is allowed to just ignore it.
Even when it is supported by the processor the XSLT spec specifies that
it has no effect on attribute values, which is where you are using it.
If you did succeed in generating an unescaped & your output would be
illegal HTML or XML, so why would you want that?
David
--
The LaTeX Companion
http://www.awprofessional.com/bookstore/product.asp?isbn=0201362996
http://www.amazon.co.uk/exec/obidos/tg/detail/-/0201362996/202-725
7897-0619804
________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
http://www.star.net.uk
________________________________________________________________________
--+------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
--+--
David Carlisle
2004-05-14 09:04:57 UTC
Permalink
I guess the complication in this case is that I'm not generating HTML or
XML, but WML which has different character escaping requirements.

No, WML is also XML and has the same requirements.

David
--
The LaTeX Companion
http://www.awprofessional.com/bookstore/product.asp?isbn=0201362996
http://www.amazon.co.uk/exec/obidos/tg/detail/-/0201362996/202-7257897-0619804


________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________
Pieter Reint Siegers Kort
2004-05-13 16:57:34 UTC
Permalink
Hi Shelli,

You do not need to use the d-o-e, since in fact, as it was pointed out,
doesn't do anything on attribute values.

Your code should work fine without it. However, you need to set the output
to html. To demonstrate, I have created the following XML:

<root>
<title>This &amp; That</title>
</root>


and XSLT:


<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="html" omit-xml-declaration="yes"/>

<xsl:template match="/">

<xsl:element name="img">
<xsl:attribute name="src">xxx</xsl:attribute>
<xsl:attribute name="alt">
<xsl:value-of select="root/title"/>
</xsl:attribute>
</xsl:element>

</xsl:template>

</xsl:transform>


which does output


<img src="xxx" alt="This &amp; That">


and that works fine in the browser. I tested on Xselerator 2.6.

HTH,
<prs/>
http://www.pietsieg.com
http://www.pietsieg.com/dotnetnuke


-----Original Message-----
From: Shelli D. Orton [mailto:***@wmode.com]
Sent: Thursday, May 13, 2004 11:29 AM
To: XSL List
Subject: [xsl] XSLT Disable-Output-Escaping Not Working

Hi,

I'm fairly new to XLST and have come across this problem. I have a template
that creates an image element as below:

<xsl:element name="img">
<xsl:attribute name="src">
<xsl:choose>
<xsl:when test="Content/Title/image">
<xsl:value-of select="Content/Title/image"
/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of
select="$defaultImage"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:attribute name="alt">
<xsl:value-of select="MetaData/title"
disable-output-escaping="yes"/>
</xsl:attribute>
</xsl:element>

When the value of MetaData/title is "This &amp; That", the &amp; is escaped
resulting in a title of "This &amp;amp; That" which the browser displays as
"This &amp; That". Shouldn't the result be "This &amp; That" which the
browser displays as "This & That"? I have used the disable-output-escaping
attribute in many other places and it has always worked before.


Thanks for any help.

Shelli


--+------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-***@lists.mulberrytech.com>
--+--
Loading...