Entity references in attributes with xsl

C

Christoph Niemann

Hello,

I want to output an element with an attribute. The attribute's value
shall contain a entity reference. Is that possible at all?

I use this source-XML and xsl-stylesheet:

[-------------xml-source-----------------]

<?xml version="1.0" encoding="utf-8"?>

<slideshow>
<slide name="01_welcome">
<p>This is a test!</p>
</slide>
</slideshow>


[-----------xsl-stylesheet---------------]

<?xml version="1.0" encoding="utf-8"?>

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

<xsl:eek:utput method="xml"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
indent="yes"
encoding="utf-8"/>

<xsl:template match="/">
<xsl:element name="html">
<xsl:element name="head"/>
<xsl:element name="body">
<xsl:apply-templates/>
</xsl:element>
</xsl:element>
</xsl:template>


<xsl:template match="slide">
<!-- This works as expected. Output is:
<p>&foo;</p>
-->
<xsl:element name="p">
<xsl:text disable-output-escaping="yes">&amp;foo;</xsl:text>
</xsl:element>

<!-- This, however, doesn't. Output is:
<img src="&amp;foo; />
-->
<xsl:element name="img">
<xsl:attribute name="src">
<xsl:text disable-output-escaping="yes">&amp;foo;</xsl:text>
</xsl:attribute>
</xsl:element>
</xsl:template>

</xsl:stylesheet>


Now, xsltproc as well as saxon do escape the &amp; within the attribute
value. Is that the intended behaviour? If so, how so I put an entity
reference in an attribute value?

Thanks in advance,

Christoph
 
M

Martin Honnen

Christoph Niemann wrote:

I want to output an element with an attribute. The attribute's value
shall contain a entity reference. Is that possible at all?
Now, xsltproc as well as saxon do escape the &amp; within the attribute
value. Is that the intended behaviour? If so, how so I put an entity
reference in an attribute value?

Saxon has an extension function:
http://saxon.sourceforge.net/saxon6.5.3/extensions.html#saxon:entity-ref
which might solve that (I haven't tried).
 
I

Imiro

Hi,

could it be question of using '%' -sign instead of '&':


<xsl:element name="img">
<xsl:attribute name="src">
<xsl:text disable-output-escaping="yes">%amp;foo;</xsl:text>
</xsl:attribute>
</xsl:element>

Since maybe its like pcdata in first and cdata in second example? Not sure though ;)

--Imiro
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top