Re: [xsl] Variables and HTML

Subject: Re: [xsl] Variables and HTML
From: "Nathan Young" <natyoung@xxxxxxxxx>
Date: Fri, 11 Mar 2005 15:47:57 -0800

We use d-o-e extensively for the use case Michael describes, namely we format the last stage of output from a Gordian publishing system. The XML instance that gets built for us quite often contains text nodes that consist of escaped HTML blobs.

We also use it for two other less common cases. One is where because of some browser vagary we want to generate and output HTML that's not valid XHTML. We can't embed it in the XSL because it would cause the XSL file to be ill-formed. Neither can we use xsl:element to construct it.

The last use case is where we do (or could) have a well formed output doc but because of the way it is constructed the XSL becomes badly formed. Most obviously this occurs where the start and end tag are generated in different xsl:templates. I've had good luck getting rid of most of these so I don't have an example on hand but I'm not quite willing to rule it out as logically impossible.

I think in all cases character maps can replace d-oe but I had some questions about the approach you outline below:

On Fri, 11 Mar 2005 10:18:54 GMT, David Carlisle <davidc@xxxxxxxxx> wrote:

In 2.0 you can always replace this by

<xsl:value-of select="'&lt;br&gt;'"/>
<xsl:value-of select="translate('&lt;br&gt;','&lt;&gt;&amp;','&#xE001;&#xE002;&#xE003;'"/>

I read this (with the addition of the closing parenthesis) as replacing less than greater than and ampersand with three unfamiliar character entities.

Together with a character mao that maps back:

<xsl:output-character character="&#xE001; string="&lt;"/>
<xsl:output-character character="&#xE002; string="&gt;"/>
<xsl:output-character character="&#xE003; string="&amp;"/>

I read this as defining instructions for the serializer to replace the unfamiliar charcters above with the appropriate output characters (<> and & in final output).

The way I read the w3c spec, it looked like you'd have to enclose those three output-character definitions in a named character map and make the serializer aware of that map by specifying the name in the use-character-map attribute of xsl:output. Did you assume that or am I missing something?

Overall I think this is really neat. For the first case (escaped html in input) we run the translate you provide above on the node. For the second two, we simply use &#xE001; in place of &lt; as needed. Is this correct?

Thanks in advance!


This works the same way except that now the information is stored in the result tree using a mechanism that is actually allowed by the specification of the datamodel (just three otherwise unused characters).

Of course the other problems with d-o-e remain, that this still only works if serialisation is tightly controlled by the XSLT engine and that in nine times out of ten it is only being used by mistake, when the stylesheet could have gone


and used an element node directly.


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:



Nathan Young
A: ncy1717
E: natyoung@xxxxxxxxx

Current Thread