Reputation: 48958
I have the following xml-node :
<name>P & P</name>
And following XSL
<a href="example.htm" >
<xsl:attribute name="title">
<xsl:value-of select="name" disable-output-escaping="yes"></xsl:value-of>
</xsl:attribute>
<xsl:value-of select="name" disable-output-escaping="yes"></xsl:value-of>
</a>
That compiles to this HTML
<a href="example.com" title="P &amp; P">
P & P
</a>
So the non-escaping worked for the value (the text between <A></A>
) but not for the attribute.
Am I missing something here?
Thanks!
Upvotes: 3
Views: 7463
Reputation: 243459
From an OP's comment:
I need this xml (P & P) in the title attribute of an HTML tag. A better solution is most welcome!
What you need to generate can be done perfectly without D-O-E.
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/*">
<a href="example.htm" title="{.}">
<xsl:value-of select="."/>
</a>
</xsl:template>
</xsl:stylesheet>
When applied on the following XML document:
<t>P & P</t>
the wanted, correct result is produced:
<a href="example.htm" title="P & P">P & P</a>
Upvotes: 2
Reputation: 48958
I've been looking around and I guess this is why : (if I understand correctly) ?
Out of the specs : (http://www.w3.org/TR/xslt)
It is an error for output escaping to be disabled for a text node that is used for something other than a text node in the result tree. Thus, it is an error to disable output escaping for an xsl:value-of or xsl:text element that is used to generate the string-value of a comment, processing instruction or attribute node; it is also an error to convert a result tree fragment to a number or a string if the result tree fragment contains a text node for which escaping was disabled. In both cases, an XSLT processor may signal the error; if it does not signal the error, it must recover by ignoring the disable-output-escaping attribute.
So disabling output for escaping an attribute is just not possible apparantly. The workaround that I see is to build a string 'by hand' as XSL - How to disable output escaping for an attribute?
Still hard to believe that I'm not missing sth. trivial here.
Upvotes: 1