This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: write out '&' instead of '&'
- To: "Sun, Christine (Cahners)" <csun at cahners dot com>
- Subject: Re: [xsl] write out '&' instead of '&'
- From: Jeni Tennison <mail at jenitennison dot com>
- Date: Thu, 18 Jan 2001 09:07:22 +0000
- CC: "'xsl-list at lists dot mulberrytech dot com'" <xsl-list at lists dot mulberrytech dot com>
- Organization: Jeni Tennison Consulting Ltd
- References: <4AF56C92A6C8D211B5F300805F6FFFDB103FF036@binbosexc001>
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi Chris,
> Using Xalan to do xml to xml transformation. Need write out special
> characters as entities, e.g. ' as apostrophe. Now the number is
> a variable, but '&#<xsl:value-of select="$entityNumber">;' will not
> work in xslt. And I don't want to write '&#<xsl:value-of
> select="$entityNumber">;'. What will be the way to get around it?
You can't usually control in XSLT the way that characters are
outputted - whether they're given as the character itself or a
character entity, or whether the character entity is a hex or decimal
one. You shouldn't usually want to: those are things to do with the
physical document and you should be thinking on a higher plane :)
But your situation, where you've got a character number and you want
to get a character out, is a bit different. This is what
disable-output-escaping is for. First, you *have* to use &
instead of '&' whenever you want an ampersand in XML. Otherwise the
parser gets all confused and thinks it should find an entity name.
If you just do:
<xsl:text>&#</xsl:text>
<xsl:value-of select="$entityNumber" />
<xsl:text>;</xsl:text>
then the XML output will be:
&#39;
which translates to the string (e.g. displayed in a browser)
'
In order to give XML output of:
'
you need to tell the XSLT processor not to escape the '&'. You do
this through the disable-output-escaping, which can be placed on
xsl:text or xsl:value-of. So if you do:
<xsl:text disable-output-escaping="yes">&#</xsl:text>
<xsl:value-of select="$entityNumber" />
<xsl:text>;</xsl:text>
then the XML output will be:
'
which translates to the string (e.g. displayed in a browser)
'
I hope that helps,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list