473,396 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Entity references in attributes with xsl

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:output 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
Jul 20 '05 #1
2 1815


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....xon:entity-ref
which might solve that (I haven't tried).

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #2
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
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Douglas Reith | last post by:
Hi There, Can someone please tell me why the XML spec states that an attribute value with an external entity is forbidden? Or point me to the appropriate document? Or better still, perhaps you...
5
by: Dean A. Hoover | last post by:
I am writing a parser for xml that will not have an associated DTD. I want to be able to handle certain character references (e.g., &copy;) in the program. When I run the following against a...
5
by: Stephan Hoffmann | last post by:
Hi, I use XML mainly as a source for HTML. HTML browsers 'know' certain entity references like &eacute; or &auml;. When I use XSL to transform XML to HTML or XML, these entities are replaced...
9
by: Jukka K. Korpela | last post by:
I noticed that Internet Explorer (6.0, on Win XP SP 2, all fixes installed) incorrectly renders e.g. &harr &euro &Omega literally and not as characters denoted by the entities, but if a semicolon...
5
by: Mateusz Loskot | last post by:
Hi, I'd like to ask how XML parsers should handle attributes which consists of &quot; entity as value. I know XML allows to use both: single and double quotes as attribute value terminator. That's...
6
by: Tuomas Rannikko | last post by:
Hello, I'm currently writing a XML processor for the fun of it. There is something I don't understand in the spec though. I'm obviously missing something important. The spec states that both...
2
by: Paquette.Jim | last post by:
Hello, I'm trying to get XUL output with an element that has an attribute containing an entity reference. Can this be done? I saw another post exactly like this...but the solutions they gave...
9
by: Max | last post by:
Hello! I would want to know if attributes values can be entity references and if the parser, during processing, can replace with blank string a non registered entity. Eg: <example...
5
by: wshaer | last post by:
Hi This is the task: and these are my classes: public class Engine{ // Declare the varibles
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.