Re: [xsl] Supressing entity expansion during XSLT transform

Subject: Re: [xsl] Supressing entity expansion during XSLT transform
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Thu, 10 Jan 2008 23:07:10 -0600
At 2008-01-11 10:29 +0530, Mukul Gandhi wrote:
[1] I want to write a transform which prevents entity expansion.

The XPath data model on which XSLT is built does not represent entity references so that any present in the input source tree cannot be preserved for serialization in the output tree. Since the result tree is based on the XPath data model, one cannot represent an entity reference in the result tree as a data model abstraction.

If you want to create entity references in the result file using XSLT 2.0, you can play with serialization using xsl:output-character and compose entity references, but since you don't know where the entity references were in the source tree, you won't know where to compose them in the output serialization.

e.g. the output of transform should be (this is an identity

<?xml version="1.0"?>
<!DOCTYPE root [
  <!ENTITY x "hello">
  <a>&x; world</a>
I get the output:

<?xml version="1.0" encoding="UTF-8"?>
  <a>hello world</a>

That is because that is the information found in the source tree. The XML processor in the XSLT processor has already resolved all aspects of syntax and has built the XPath node tree with the information found in the source file (but not the syntax found in the source file).

Constructs such as entity references and CDATA sections are merely aspects of syntax, not of information.

But I want the output as specified in [1] above.

What is the solution to this problem?

Using a language other than XSLT. I believe the DOM supports entity references.

I can use XSLT 2.0.

Not for this problem you can't.

I hope this helps.

. . . . . . . . . . . . Ken

Comprehensive in-depth XSLT2/XSL-FO1.1 classes: Austin TX,Jan-2008
World-wide corporate, govt. & user group XML, XSL and UBL training
RSS feeds:     publicly-available developer resources and training
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Cancer Awareness Nov'07
Legal business disclaimers:

Current Thread