[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Entities: The worst of both worlds :-(

Subject: Re: Entities: The worst of both worlds :-(
From: Mike Brown <mike@xxxxxxxx>
Date: Mon, 1 Oct 2001 12:19:41 -0600 (MDT)
xslt preserve entities
Nicholas Waltham wrote:
> I have an XSL which translates from one form of XML to another,
> I would like to preserve the entities in XML

Another FAQ. There is nothing you can do because:

a.) It is the XML parser that resolves entities, by design; and

b.) the XPath/XSLT data model, which is based on the data that
    is typically exposed by a parser (SAX moreso than DOM), does
    not have any structures for entity references.

> Secondly, if I include enties in the XSL, they stay as
> entities in the final output.

The stylesheet is parsed first, so any entity references go away
before the XSLT processor sees them. Output of *character*
entity references like &nbsp; in HTML occurs automatically when
the XSLT processor is serializing the raw Unicode character data
in the result tree (assuming the output is HTML). In XML output,
only numeric character references are generated, and usually
only when the character cannot be represented in the desired
output encoding.

All other examples of entity reference output either use
processor-specific extensions, or they are improper simulations
of entity references, generated from text nodes that rely on the
processor's optional support for the disable-output-escaping="yes"
attribute allowed on xsl:value-of and xsl:text.

> <xsl:text>&amp;</xsl:text><xsl:value-of
> select="@entval"/><xsl:text>;</xsl:text>

You could put disable-output-escaping on that first text node,
though any use of disable-output-escaping is considered risky
and inelegant, as you could easily create something that is
not well-formed XML.

The usual response to this is to question why you feel it is so
important to preserve entity references in the first place
--particularly character entity references. And the ideal
solution, rather than bending XSLT to do something it wasn't
designed to do, is to output pseudo-entity-references in your
own unambiguous format, that you can do a quick search and
replace action upon after you're done with the XSLT processing.
Like just output %%foo%% and worry about converting it to &foo;
in a post-processor.

   - Mike
____________________________________________________________________________
  mike j. brown, fourthought.com  |  xml/xslt: http://skew.org/xml/
  denver/boulder, colorado, usa   |  personal: http://hyperreal.org/~mike/

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.