[Yanel-usage] [XSLT]: Escaping <
Josias Thöny
josias.thoeny at wyona.com
Fri Nov 10 10:26:20 CET 2006
Hi Paloma,
Maybe you could try something like this:
<description>
<xsl:apply-templates select="atom:content/*"/>
</description>
<xsl:template match="*[namespace-uri()='http://www.w3.org/1999/xhtml']">
<<xsl:value-of select="local-name()"/>>
<xsl:apply-templates/>
</<xsl:value-of select="local-name()"/>>
</xsl:template>
It explicitely converts all xhtml tags into an escaped form.
(Currently this example does not work with attributes yet.)
It's not a very nice solution, but ATM I have no better idea.
About the xsl:value-of, I thought that it always removes the tags and
only outputs the text and attribute nodes of the input. Did it output
the complete elements in your first example, like e.g
<xhtml:p>foo</xhtml:p> ?
hth,
josias
On Fri, 2006-11-10 at 09:44 +0100, Paloma Gomez wrote:
> 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: <.
>
> 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
>
> _______________________________________________
> Yanel-usage mailing list
> Yanel-usage at wyona.com
> http://wyona.com/cgi-bin/mailman/listinfo/yanel-usage
>
More information about the Yanel-usage
mailing list