Disable output escaping not working for attribute in xslt

attributesxslt

I have the following xml-node :

<name>P &amp; 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;amp; P">
  P &amp; 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!

Best Answer

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 &amp; P</t>

the wanted, correct result is produced:

<a href="example.htm" title="P &amp; P">P &amp; P</a>
Related Topic