I have got the following content in my XML:
<MyElement> Cats&apos; eyes </ MyElement >
When I use the following code in my XSLT 1.0:
<xsl:value-of select="MyElement" />
The output is
Cats' eyes
But I want to get
Cats’ eyes
I tried
<xsl:value-of select='translate(MyElement, "&apos; ", "' ")' />
But it didn’t work , the result was ca’ ey with some eliminated characters!!!!
Any thought?
Thanks
It's simple, just add
disable-output-escaping="yes"
Your first problem is that it appears your content has been "double escaped". The entity for an apostrophe is
'
, not&apos;
.Your attempt to replace characters with
translate()
did not work, because it works differently than you are expecting. It is not a find/replace method. You specify a list of characters in the second argument and then the corresponding character to translate each one into in the third parameter. If there is no corresponding character in the list of characters in the third parameter then it will be removed.You will need to use a recursive template to perform the character replacement.
For example:
Of course, with XSLT 2.0 you could just use the replace() function: