saxon:escape-NCName
Converts any string to a valid NCName, by escaping characters that would otherwise be invalid.
escape-NCName($input as xs:string) ➔ xs:NCName
Arguments | |||
| $input | xs:string | The input string to be converted |
Result | xs:NCName |
Namespace
http://saxon.sf.net/
Saxon availability
Requires Saxon-PE or Saxon-EE. Implemented since Saxon 11.
Notes on the Saxon implementation
Available since Saxon 11.
Details
If the supplied string is a valid NCName, it is returned unchanged.
The zero-length string is converted to a single underscore, "_"
.
An underscore is converted to a pair of underscores, "__"
.
A character that would not be valid in an NCName (or, if it is the first character,
at the start of an NCName) is converted to the form "_XXX_"
where XXX
is the shortest hexadecimal representation of the Unicode codepoint. For example, "£"
becomes "_a3_"
. Lower case is used for digits a-f.
The rules for NCName characters are those in XML 1.0 Fifth Edition (which match the rules in XML 1.1).
For example, saxon:escape-NCName("date of birth")
returns "date_20_of_20_birth
.
The function is primarily intended for use when converting JSON to XML.
The reverse conversion is available from the function saxon:unescape-NCName
.