[Yanel-usage] [XSLT]: Escaping <

Paloma Gomez paloma.gz at gmail.com
Fri Nov 10 09:44:57 CET 2006


Hi all,

I'm implementing an XSLT stylesheet to convert an atom feed to an RSS
feed. The atom feed contains xhtml tags inside its tags but RSS does
not allow < > within its tags. If one wants to insert <, then it has
to be escaped: &lt;.

This is what I would like to do:

[code]
<xsl:output method="xml" encoding="UTF-8"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd "
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"/>

[...]

<description>
   <xsl:value-of select="atom:summary"/>
   <xsl:value-of select="atom:content/*"/>
</description>

[/code]

The problem is that doing so the xslt processor does not escape the <, >.

I don't understand why, though. Quoting the W3C spec:

[quote]
7.6.1. Generating text with xsl:value-of
The xsl:value-of element is instantiated to create a *text node* in
the result tree
[...]
16.4 Disabling Output Escaping
Normally, the xml output method escapes & and < (and possibly other
characters) when outputting *text nodes*.
[/quote]

So I understand that the default behaviour is escaping unless you tell
the xslt processor explicitly not to escape.

I have found this workaround with the help of David:

[code]
<xsl:variable name="atomSummary">
  <xsl:value-of select="atom:summary"/>
</xsl:variable>
<xsl:variable name="atomContent">
   <xsl:value-of select="atom:content/*"/>
</xsl:variable>

<description>
  <xsl:value-of select="concat($atomSummary, $atomContent)"/>
</description>
[/code]

However, it removes the xhtml tags.

Is there a way force the escaping of < >?

Thanks,

Paloma



More information about the Yanel-usage mailing list