I am using an XSL document to pretty print my RSS feed. However, special characters don't parse - they appear within the feed as   and &

What line(s) do I need to specify in my RSS and XSL XML documents in order to get these to work? It's my understanding that & " < > should work by default but I need to do extra to work to map   to a space.

Dani AI

Generated

A short, practical summary and safer options to the suggestions already here: 's quick fix with disabled output escaping works as a stopgap, and was right that declaring entities or using numeric references can address the underlying issue — but both approaches have important caveats and better alternatives for production feeds.

Disable-output-escaping is explicitly part of XSLT, but the spec warns it is fragile: it only has an effect if the transformer controls serialization, processors may ignore it, and it can break when the result is used as a tree rather than serialized immediately. Use it only as a last resort. (w3.org)

A more robust approach is to control serialization instead of trying to inject markup into text nodes. Use an appropriate xsl:output and a character map so non-breaking spaces (or other characters) are serialized the way you want. For example, you can declare an output definition that uses a named character map and map the NBSP character to the entity you prefer:

<xsl:output method="html" encoding="UTF-8" use-character-maps="htmlChars"/>

<xsl:character-map name="htmlChars">
  <xsl:output-character character="&#x00A0;" string="&amp;nbsp;"/>
</xsl:character-map>

Character maps are part of XSLT serialization and are safer than disabling escaping. (w3.org)

If the RSS description elements contain escaped HTML fragments, the best solution is to parse those fragments into nodes and copy them into the result tree (so markup is real nodes, not escaped text). Modern XPath/XSLT offer fn:parse-xml / fn:parse-xml-fragment for this; older processors often provide vendor extensions (or you can pre-parse before transforming). Also remember that named entities like &nbsp; only work if the parser actually reads a DTD — many non-validating readers ignore external entity declarations, so relying on a DOCTYPE can fail. (w3.org)

Recommendation: avoid disable-output-escaping for production. Prefer serialization controls (xsl:output + character maps) or proper parsing of embedded HTML; set the stylesheet output encoding to match your feed (e.g., UTF-8) so literal Unicode characters are preserved. (w3.org)

Recommended Answers

All 6 Replies

In your dtd try this

<!ENTITY &nbsp; " ">

I was reading up about that but I haven't tried it yet. What I'm most in need of is getting &amp; to work, but from what I understand, it should by default? I'm using UTF-8 if that matters.

Entities such as &amp; and &quote; will need to be specified into the dtd but you could always use the hex value so for a single quote you could use &39; and whitespace you could use &#160; this will always be transformed for you with no problems and saves you declaring the entities in the dtd.

sorry a space is

&#160;

and a single quote qould be

&#39;

Thank you for your help. I did some research and the following worked:

I replaced

<xsl:value-of select="description" />

with

<xsl:value-of select="description" disable-output-escaping="yes" />

great tip, thx for the help

Thank you for your help. I did some research and the following worked:

I replaced

<xsl:value-of select="description" />

with

<xsl:value-of select="description" disable-output-escaping="yes" />
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.