transform.XMLEscape
Returns the given string, removing disallowed characters then escaping the result to its XML equivalent.
- Syntax
- transform.XMLEscape INPUT
- Returns
- string
Usage
The transform.XMLEscape function removes disallowed characters as defined in the XML specification, then escapes the result by replacing these characters with HTML entities:
"→"'→'&→&<→<>→>\t→	\n→
\r→
When you print the result in an HTML template, Hugo escapes the entities again. To prevent this, pass the result through the safe.HTML function. See safe types for details.
Examples
{{ transform.XMLEscape "<p>abc</p>" }} → <p>abc</p>Comparing the result with and without safe.HTML, showing the raw HTML output:
{{ transform.XMLEscape "<p>abc</p>" }} → &lt;p&gt;abc&lt;/p&gt;
{{ transform.XMLEscape "<p>abc</p>" | safeHTML }} → <p>abc</p>In an RSS template:
layouts/rss.xml
<description>{{ .Summary | transform.XMLEscape | safeHTML }}</description>Last updated:
October 27, 2026
:
content: Standardize print and render usage (c165900b1)
Improve this page