preventing an entity-reference to be resolved (output method XML)

J

Joris Gillis

Hi everyone,

I have this stylesheet:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:eek:utput method="xml"/>
<xsl:template match="/">
<node>&apos;</node>
</xsl:template>
</xsl:stylesheet>

My goal is to get this output:
<?xml version="1.0" encoding="UTF-8"?><node>&apos;</node>


I've tried '&amp;apos;' , '&apos;'
I tried to do it with custom ENTITY's in the DOCTYPE.
I tried with CDATA sections.
But non of it works.

I know it works if the output method is 'text', but it has to work in
'xml' too.


Any help or comments greatly appreciated...
 
M

Martin Honnen

Joris Gillis wrote:

I have this stylesheet:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:eek:utput method="xml"/>
<xsl:template match="/">
<node>&apos;</node>
</xsl:template>
</xsl:stylesheet>

My goal is to get this output:
<?xml version="1.0" encoding="UTF-8"?><node>&apos;</node>


I've tried '&amp;apos;' , '&apos;'
I tried to do it with custom ENTITY's in the DOCTYPE.
I tried with CDATA sections.
But non of it works.

I know it works if the output method is 'text', but it has to work in
'xml' too.

I think within the XSLT 1.0 standard there is nothing for you to mandate
whether such a character is serialized in UTF-8 as an enity reference or
literally. However some processors have extensions to achieve that, for
instance Saxon:
http://saxon.sourceforge.net/saxon6.5.3/extensions.html#saxon:entity-ref
where the documentation says it is meant for HTML entity references but
maybe you can use it for other output methods as well.
 
A

Andy Dingley

I know it works if the output method is 'text', but it has to work in
'xml' too.

As far as I know, there is no way to do this in XSLT. It is an _XML_
problem - in XML the entity reference and the character itself are
seen as equivalent and so there is never any need (sic) to control
the choice explicitly.

You need to modify the behaviour of the XML serialiser that is used to
generate the output document. I've done this, but I had to change the
serialiser code to do so. Maybe some other tools will already allow
this to be controlled ? I was just working with what I had.

As it's &apos; you're after (and if this is all you're after), an
output mode of "HTML" might work for you. &apos; is defined in XML,
but not in the HTML DTDs.
 
J

Joris Gillis

Thank you, Martin and Andy, for your replies.

It seems to be there is indeed (not yet) a standard-compliant way to solve
this.

Meanwhile, I figured out that
<xsl:text disable-output-escaping="yes">&amp;apos;</xsl:text>
returns the returns the result I want.

But the XSLT1.1 specification clearly states that it is illegal to use
'disable-output-escaping' with attribute nodes, which is actually what I'm
trying to achieve.

The actual problem I had:
OpenOffice.org (1.1.3) crashes when it finds a single quote (') in font
declaration attributes in the content.xml part of a file. It does not
accept anything else than '&apos;'. So generating content.xml with XSLT1.1
directly now seems impossible.


About the trick to set the ouptut method to 'HTML' , it doesn't work with
me. (I'm using AltovaXslt)


regards,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top