[dsdl-discuss] Re: Entity renaming

From: G. Ken Holman <gkholman@CraneSoftwrights.com>
Date: Wed Dec 14 2005 - 04:43:57 UTC

At 2005-12-13 19:35 +0000, Martin Bryan wrote:
>Ken
> > >What I did find, however, was that if I put
> > >the replacement string in a variable and then invoked that I got what I
> > >wanted.
> >
> > Not sure what you are saying there, but whatever it is I'm guessing
> > you are going beyond the bounds of the XPath data model.
>
>It seems that variables are not parsed. If you ask to send the contents of a
>variable to the output stream it will appear exactly as defined, without any
>of the replacements taking place (hopefully)

I'm keeping this on the list in case anyone else recognizes what is
going on because I'm very confused. Variables are defined by the use
of the XPath data model for the stylesheet, so I can see no way in
which entity references are ever preserved.

Can you create a short 10-line stylesheet that illustrates what you
are referring to when you talk about the contents of variables not
having replacements (I'm assuming entity replacements) taking
place? I'm anxious to see where I'm confused.

> > > > What is the use case for entity renaming?
> > >
> > >Two main ones:
> > >
> > >1) Entity reference retention (&nbsp; -> &nbsp; rather than &#160;)
> > >2) Localization/easier comprehension for people with limited English
>(&et;
> > >or &and; rather than &amp;)
> >
> > I'm quite sure both of those are covered in XSLT 2 character
> > maps. Both of them are mapping a Unicode character into an entity
> > reference ... not preserving input entities nor creating an entity
> > for a string of characters.
>
>1) is most definitely not. You can't preserve entities by mapping &#160;
>back to &nbsp;

Right, you can't "preserve" entities as I've said all along ... but I
have said you can make the assumption that if you see &#160; (or the
equivalent) in the result tree that it gets serialized as &nbsp; as in:

T:\>type martin.xsl
<!DOCTYPE xsl:stylesheet [
<!ENTITY nbsp "&#xa0;">
]>
<xsl:stylesheet
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     version="2.0">

<xsl:output use-character-maps="martin"/>

<xsl:character-map name="martin">
   <xsl:output-character character="&#160;" string="&amp;nbsp;" />
</xsl:character-map>

<xsl:template match="/">
   <xsl:text>An NBSP between X's: X&nbsp;X</xsl:text>
</xsl:template>

</xsl:stylesheet>
T:\>java -jar p:saxon8.jar martin.xsl martin.xsl
<?xml version="1.0" encoding="UTF-8"?>An NBSP between X's: X&nbsp;X
T:\>

Note, however, that the output created above is *not* well
formed! That's one thing I mentioned earlier about worries about the
result tree when playing with the serialization.

>2) you can do now I think it through a bit further. But you could not
>replace &et; with &amp;.

You can if you make assumptions about which each one is transformed to:

T:\>type martin2.xml
<!DOCTYPE xsl:stylesheet [
<!ENTITY et "&#38;amp;">
<!ENTITY this "&#xa1;">
]>
<in>
An ampersand between X's: X&et;X
A this changed to a that: X&this;X
</in>

T:\>type martin2.xsl
<xsl:stylesheet
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     version="2.0">

<xsl:output use-character-maps="martin"/>

<xsl:character-map name="martin">
   <xsl:output-character character="&amp;" string="&amp;amp;" />
   <xsl:output-character character="&#xa1;" string="&amp;that;" />
</xsl:character-map>

<xsl:template match="/">
   <xsl:copy-of select="."/>
</xsl:template>

</xsl:stylesheet>
T:\>java -jar p:saxon8.jar martin2.xml martin2.xsl
<?xml version="1.0" encoding="UTF-8"?><in>
An ampersand between X's: X&amp;X
A this changed to a that: X&that;X
</in>
T:\>

I hope this helps.

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

--
Upcoming XSLT/XSL-FO hands-on courses:  Denver,CO March 13-17,2006
World-wide on-site corporate, govt. & user group XML/XSL training.
G. Ken Holman                 mailto:gkholman@CraneSoftwrights.com
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/d/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Cancer Awareness Aug'05  http://www.CraneSoftwrights.com/d/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal
--
DSDL members discussion list
To unsubscribe, please send a message with the
command  "unsubscribe" to dsdl-discuss-request@dsdl.org
(mailto:dsdl-discuss-request@dsdl.org?Subject=unsubscribe)
Received on Wed Dec 14 05:45:24 2005

This archive was generated by hypermail 2.1.8 : Fri Dec 16 2005 - 01:13:01 UTC