SPFE Documentation | Collections > SPFE Function Reference > escape-for-xml
Function: escape-for-xml
escape-for-xml(string as item()*) as item()*
- Description
-
Takes an input string and escapes the < and & characters so that the string can be inserted into an XML document. For example, given the string:
<name>Five & Dime</name>
It will return the string
<name>Five & Dime</name>
This is useful for inserting examples of XML into an XML document.
- Return value
-
Return type: item()*
The input string with the < and & characters escaped.
- Source file
-
$SPFEOT_HOME/1.0/scripts/common/utility-functions.xsl
Parameters
- string
-
Type: item()*
The string to be escaped for XML.
Definition
<xsl:function name="sf:escape-for-xml"> <xsl:param name="string"/> <xsl:analyze-string select="string($string)" regex="<|&"> <xsl:matching-substring > <xsl:choose > <xsl:when test=".='<'"><</xsl:when> <xsl:when test=".='&'">&</xsl:when> </xsl:choose> </xsl:matching-substring> <xsl:non-matching-substring > <xsl:value-of select="."/> </xsl:non-matching-substring> </xsl:analyze-string> </xsl:function>