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→
The function returns a string. Go’s html/template package escapes strings in most contexts, which escapes the entities in the result again. To render the result as is, pass it through the safe.HTML function.
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 21, 2026
:
content: Apply style guide to transform functions (3625f720a)
Improve this page