473,790 Members | 2,421 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is it possible NOT to replace entity references?

Hi,

I use XML mainly as a source for HTML. HTML browsers 'know'
certain entity references like é or ä.

When I use XSL to transform XML to HTML or XML, these entities are replaced
by what they refer to.

Is there a way to avoid that?

Two reasons to avoid that:
- On my linux machine xsltproc replaced the entities in a way that
my browser did not correctly display the resulting HTML
(I updated my linux distribution and it now works).

- &lt; is replaced by < and the output is no longer valid XML/HTML
I worked with the Python xml.sax module today,
which had the same 'issue'. I can of course perform the
inverse substitution before I write to the result document,
but that seems like a lot of unnecessary work.

Any hints?

Thanks, Stephan

Sep 5 '05 #1
5 2327


Stephan Hoffmann wrote:

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
by what they refer to.

Is there a way to avoid that?
XSLT/XPath 1.0 at least which is the current version and the one
implemented by lots of processors and in wide-spread use does not
provide anything in its data model or in its instructions to create
entity references and to ensure that these are preserved and not
replaced by the entity content when the result of a transformation is
serialized.
You would need to look at a specific XSLT processor and check whether it
provides any mechanisms outside the standards to deal with entity and
entity references.
Saxon 6 has an extension function documented here:
<http://saxon.sourcefor ge.net/saxon6.5.4/extensions.html #saxon:entity-ref>
Two reasons to avoid that:
- On my linux machine xsltproc replaced the entities in a way that
my browser did not correctly display the resulting HTML
(I updated my linux distribution and it now works).

- &lt; is replaced by < and the output is no longer valid XML/HTML


But &lt; and &gt; are references to entities predefined in XML and
certainly if any application supposed to output XML or HTML outputs &lt;
as a plain '<' character then the application is seriously broken.
This is a different issue, those characters '<' and '>' are obviously
special as they delimit tags in both XML and HTML and therefore need to
be escaped as &lt; respectively &gt;.
&auml; in HTML 4 stands for the character 'ä' and that has no special
meaning in XML or HTML so if an XSLT processor or other application
supposed to output XML or HTML simply inserts 'ä' instead of &auml; in a
document properly encoded and with the proper encoding used and declared
then there are no problems with well-formedness (or even validity).

--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 5 '05 #2
Stephan Hoffmann (sh*@twmi.rr.co m) wrote:
: 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
: by what they refer to.

: Is there a way to avoid that?

Perhaps judicious use of the "disable-output-escaping" attribute would
help.

That attribute can be specified in various template tags, including <text>
and <value-of> (perhaps others).

It takes the value of either "yes" or "no".

--

This programmer available for rent.
Sep 5 '05 #3
Hi,

thanks for the detailed explanation.

You are right, these are two 'issues', I confused them because
the Python SAX parser I use replaces both the predefined and the not
predefined entity references, which is ok. I simply assumed an XSLT
processor would also replace both, but that assumption is probably wrong.

I don't know why I prefer &auml; over 'ä', maybe because 7-bit
ASCI seems to be more portable, but I can't really find a use case
where 'ä' would be less portable.

Thanks, Stephan

Martin Honnen wrote:


Stephan Hoffmann wrote:

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 by what they refer to.

Is there a way to avoid that?


XSLT/XPath 1.0 at least which is the current version and the one
implemented by lots of processors and in wide-spread use does not
provide anything in its data model or in its instructions to create
entity references and to ensure that these are preserved and not
replaced by the entity content when the result of a transformation is
serialized.
You would need to look at a specific XSLT processor and check whether it
provides any mechanisms outside the standards to deal with entity and
entity references.
Saxon 6 has an extension function documented here:
<http://saxon.sourcefor ge.net/saxon6.5.4/extensions.html #saxon:entity-ref>
Two reasons to avoid that:
- On my linux machine xsltproc replaced the entities in a way that
my browser did not correctly display the resulting HTML
(I updated my linux distribution and it now works).

- &lt; is replaced by < and the output is no longer valid XML/HTML


But &lt; and &gt; are references to entities predefined in XML and
certainly if any application supposed to output XML or HTML outputs &lt;
as a plain '<' character then the application is seriously broken.
This is a different issue, those characters '<' and '>' are obviously
special as they delimit tags in both XML and HTML and therefore need to
be escaped as &lt; respectively &gt;.
&auml; in HTML 4 stands for the character 'ä' and that has no special
meaning in XML or HTML so if an XSLT processor or other application
supposed to output XML or HTML simply inserts 'ä' instead of &auml; in a
document properly encoded and with the proper encoding used and declared
then there are no problems with well-formedness (or even validity).


Sep 6 '05 #4
In article <kM************ *******@tornado .ohiordc.rr.com >,
Stephan Hoffmann <sh*@twmi.rr.co m> wrote:
You are right, these are two 'issues', I confused them because
the Python SAX parser I use replaces both the predefined and the not
predefined entity references, which is ok. I simply assumed an XSLT
processor would also replace both, but that assumption is probably wrong.
It doesn't really make sense to contrast a parser with an XSLT
processor.

An XSLT processor will use a parser to read the document and
stylesheet, and that parser must replace entity references with the
characters they represent as it reads the files. Your problem is with
what happens on *output*: whether the program replaces characters with
entity references.
I don't know why I prefer &auml; over 'ä', maybe because 7-bit
ASCI seems to be more portable, but I can't really find a use case
where 'ä' would be less portable.


XML parsers have to be able to handle UTF-8, so it won't be a problem
for any XML tools. It may be a problem for other tools (or humans)
that only understand ASCII. You can use the encoding attribute on
xsl:output to tell the XSLT processor what output encoding to use
(though it isn't guaranteed to support them all). If you tell it
to use ASCII and you output a non-ascii character, it should use
a numeric characters reference. It can't use &auml; when outputting
XML because in general that won't be defined, so it will output
ä or &#xE4;.

-- Richard
Sep 6 '05 #5
Stephan Hoffmann wrote:
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 by what they refer to.

Is there a way to avoid that?
Not really: this is what transformation is *supposed* to do.
Martin suggested some processors might provide facilities for
doing this, but I haven't seen them in operation.
Two reasons to avoid that:
- On my linux machine xsltproc replaced the entities in a way that
my browser did not correctly display the resulting HTML
(I updated my linux distribution and it now works).

- &lt; is replaced by < and the output is no longer valid XML/HTML


The topic is covered in the FAQ at http://xml.silmaril.ie/authors/cdata/

///Peter
Sep 7 '05 #6

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

Similar topics

12
3983
by: Jeff Lanfield | last post by:
First of all, I apologize if coalescing is not the right term to describe my problem. I have a tree where each node has the same set of attributes (is the same entity) but child nodes should inherit attribute values from parent node. for example, say I have the following table: (nodeId int , color varchar, phone varchar) with two rows 5, "GREEN", "555-1212"
1
2512
by: David Madore | last post by:
Hi! Anyone in for a Byzantine discussion on XML well-formedness? Here's the situation: test.xml contains --- test.xml: cut after --- <?xml version="1.0" encoding="us-ascii"?> <!DOCTYPE foobar > <foobar />
11
2395
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 know of a work around? It is a little frustrating that the normally powerful external entities are limited in this fashion. Example (myextent.txt contains just one word without a CR):
9
2189
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 is appended to each of the entity references, they work. I'm pretty sure that previous versions of IE rendered them by the specifications. I first thought this has something to do with XML (i.e. maybe IE pretends to play a little bit of XML...
3
2277
by: bgeci | last post by:
I have problem with Entity definition. ____________________________________________ my file "test.xml" ---- <?xml version="1.0" ?> <!DOCTYPE message > <message>&Ep;</message> ---- IE6 Error mesage ???? 'Parameter entities cannot be used inside markup declarations in an
1
1076
by: Neil | last post by:
I want to be able to provide entity data to my XmlDocument from the runtime environment. I have an XML based report which I load into an XmlDocument object and feed to a PDF generator. Within the report I want to define a number of entity references (name, age, geneder etc.). When I load the XML file I would like to be able to specifiy these entity values 'on the fly' (they are available a variables within the runtime environment). ...
2
1299
by: jesl | last post by:
Group, I have created a User Control with the property "Html" of type string. If I declare this control on an ASPX page with the value "<b>This is an entity: &lt;</b>" for the property "Html", the ASP.NET parser seems to automatically convert the entity reference "&lt;" to it's corresponding character value "<". For example, if the tagprefix and tagname for the user control is "dn" and "test":
6
2078
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 Internal General and Character references are included when referenced in content. And "included" means: <quote>
9
2117
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 val="&entity1;&entity2;"></example> &entity1; is a registered internal/external general entity
0
9666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9512
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10413
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10145
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9986
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9021
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3707
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.