This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

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


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   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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]