Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

xsl:entity-ref

4 views
Skip to first unread message

Mike Kraley

unread,
Oct 19, 1999, 3:00:00 AM10/19/99
to
I continue to be plauged by the problem of how to make an XSL transform
output a character entity, e.g.   Just saying:

<xsl:template match="...">&nbsp;</xsl:template>

converts the entity in the xsl document and so inserts a space in the
output. What I want is to insert the characters "& n b s p ;" to get
inserted in the output.

putting the &nbsp in a CDATA results in the ampersand being quoted as &amp;

In perusing some of the non-microsoft XML/XSL discussions, I see mention of
an xsl command called xsl:entity-ref which looks like it is exactly what I
want. But it is not mentioned in the Microsoft documentation.

But then I happened to notice that Microsoft itself uses that command in
defaultSS.xsl, the stylesheet used to expand XML documents in IE5. How nice
of them.

So I tried it - e.g. <xsl:entity-ref name="nbsp"/>. Even more interesting.

If I use .transformNode, it works fine! just what I want. But if I use
.transformNodeToObject, then I get a parsing error on the output DOM,
reporting "Reference to undefined entity 'nbsp'". This makes sense, because
I haven't, in fact, defined it.

So how do I define it? I thought entities can only be defined in a DTD, and
I'm not using one. Even if I did, then what do I define the output to be? Do
I have to define each special character? or is there some way I can refer to
the HTML spec?

I also tried variations on the theme of <xsl:entity-ref name="#160"/>, since
that's the numeric equivalent (in a MS browser anyway), and you don't have
to define numeric character entity refs (I believe), but they all resulted
in an error during the transform operation.

...Mike

Microsoft

unread,
Oct 19, 1999, 3:00:00 AM10/19/99
to
transformNodeToObject is running into a completely different problem. Using
&nbsp; in an XML document is not valid XML unless the entity nbsp is defined
in a DTD as follows:

<!DOCTYPE foo [
<!ENTITY nbsp "&#160;">
]>
<foo>&nbsp;</foo>

You will also probably want to turn of validateOnParse in the target
document object.

"Mike Kraley" <mi...@kraley.com> wrote in message
news:s0pfo8...@corp.supernews.com...

Mike Kraley

unread,
Nov 4, 1999, 3:00:00 AM11/4/99
to
OK, that makes sense.

But how do I get XSL to insert a doctype node in the output. I previously
corresponded with you about the difficulty of inserting a DOCTYPE via the
DOM; it seems that it is no easier via XSL, unless I am missing something.

I tried pre-loading the output document with a simple document (as you
describe) before executing the transformNodeToObject, but that seems to get
blown away when the transform takes place.

I tried turning off validateOnParse, but I still get the error.

And, am I correct that if I use any part of a DOCTYPE, then I need a
complete DTD? iow, is there any way to define an entity, but still say that
I don't care about the structure of the document (as if I had not specified
a DOCTYPE)?

thanks

...Mike

Microsoft <anon...@microsoft.com> wrote in message
news:erR2fHnG$GA.249@cppssbbsa05...

0 new messages