473,326 Members | 2,173 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,326 software developers and data experts.

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 2287


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.sourceforge.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.com) 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.sourceforge.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.com> 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
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...
1
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...
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...
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...
3
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...
1
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...
2
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...
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...
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.