Skip to content Skip to sidebar Skip to footer

How Do I Unescape Html, Then Transform It With Xslt?

I'm fairly new to XSLT, and I have a large XML document that I'm trying to transform into ICML (an XML variant used by Adobe InDesign). The relevant portion of the source document

Solution 1:

I am not sure what your question is. Escaped text is not XML and cannot be processed as XML. There are no nodes you can select, so the best you can hope for is a result of:

<Content>
<p>This text includes escaped HTML entities.</p>
</Content>

which is easy to get using:

<Content><xsl:value-ofselect="."disable-output-escaping="yes"/></Content>

If you want to remove the wrapping element, you must do so using string functions. If you can be sure that the wrapping element is <p> (or any other tag with string-length of 1), you can do:

<Content><xsl:variablename="text"select="normalize-space(.)" /><xsl:value-ofselect="substring($text, 4, string-length($text) - 7)"disable-output-escaping="yes"/></Content>

Alternatively, save the result of this transformation to a file, and process the resulting file. However, this requires that the resulting file be a well-formed XML document - I understand you cannot be sure of that.

Post a Comment for "How Do I Unescape Html, Then Transform It With Xslt?"