tags:

views:

637

answers:

2

I need to unescape xml characters from inside of XML nodes with help only XSLT transformation . I have <text>&lt;&gt;and oyher possible characters</text> and need to get it as valid formatted html when i placed it inside of body tag..

+2  A: 
<xsl:template match="text">
  <body>
    <xsl:value-of select="." disable-output-escaping="yes" />
  </body>
</xsl:template>

Note that the output is not guaranteed to be well-formed XML anymore.

Tomalak
I would also note that disable-output-escaping is an optional serialization feature. It is not supported for instance by the XSLT processor used in Mozilla browsers like Firefox as those directly render the result tree and don't serialize it.
Martin Honnen
A: 

I haven't found an answer to this question. So I came to the conclusion that this is no way to do this. I found workaround for this problem, unescaping file on server side.

Artic
Erm... What's wrong with my answer? This *is* the way to do what you ask for.
Tomalak
Artic
Which is *exactly* what "disabling the output escaping" means. If your input would be correctly escaped, which it isn't, you would have `<` and `>`, and these would turn to `<` and `>`. And then you would have ` `, which would turn to ` `. And that's a perfectly legal HTML escape sequence that does not need any further translation to " ". The fact that you have ` ` means your input is broken to begin with.
Tomalak
And besides, you were not asking how to evaluate HTML named entities into actual characters, your question title is "How to unescape XML characters with help of XSLT?" and the only XML "special characters" are `<,>
Tomalak
Ok. You are right.
Artic