xsl-list
[Top] [All Lists]

Re: [xsl] Supressing entity expansion during XSLT transform

2008-01-11 00:22:09
Thanks Ken for the useful explanation.

I am trying to use Saxon 9 extension, saxon:character-representation
(with value, entity). But I am having problem with getting the output
right. Could somebody, please help me with this.

On Jan 11, 2008 10:37 AM, G. Ken Holman 
<gkholman(_at_)cranesoftwrights(_dot_)com> wrote:
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.

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

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

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

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


-- 
Regards,
Mukul Gandhi

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--