SPFE Documentation | Collections > SPFE Function Reference > pct-decode
Function: pct-decode
pct-decode(in as xs:string, seq as xs:string*) as xs:string?
- Description
-
Takes a string encoded using percent-encoding (also know as URL encoding) and returns the decoded string. Adapted from code published by James A. Robinson at http://www.oxygenxml.com/archives/xsl-list/200911/msg00300.html.
This is a recursive polymorphic function. You call the version of the function that takes one parameter, in. The second version of the function is called recursively by the first version to complete the decoding of the input string. It takes a second parameter, seq. You should not call this version of the function from your code.
- Return value
-
Return type: xs:string?
The decoded string.
- Source file
-
$SPFEOT_HOME/1.0/scripts/common/utility-functions.xsl
Parameters
- in
-
Type: xs:string
The string to be decoded.
- seq
-
Type: xs:string*
Used internally by the function during recursion. Do not use this parameter in your code.
Definition
<xsl:function name="sf:pct-decode" as="xs:string?"> <xsl:param name="in" as="xs:string"/> <xsl:sequence select="sf:pct-decode($in, ())"/> </xsl:function>
<xsl:function name="sf:pct-decode" as="xs:string?"> <xsl:param name="in" as="xs:string"/> <xsl:param name="seq" as="xs:string*"/> <xsl:choose > <xsl:when test="not($in)"> <xsl:sequence select="string-join($seq, '')"/> </xsl:when> <xsl:when test="starts-with($in, '%')"> <xsl:choose > <xsl:when test="matches(substring($in, 2, 2), '^[0-9A-Fa-f][0-9A-Fa-f]$')"> <xsl:variable name="s" as="xs:string" select="substring($in, 2, 2)"/> <xsl:variable name="d" as="xs:integer" select="sf:hex-to-dec(upper-case($s))"/> <xsl:variable name="c" as="xs:string" select="codepoints-to-string($d)"/> <xsl:sequence select="sf:pct-decode(substring($in, 4), ($seq, $c))"/> </xsl:when> <xsl:when test="contains(substring($in, 2), '%')"> <xsl:variable name="s" as="xs:string" select="substring-before(substring($in, 2), '%')"/> <xsl:sequence select="sf:pct-decode(substring($in, 2 + string-length($s)), ($seq, '%', $s))"/> </xsl:when> <xsl:otherwise > <xsl:sequence select="string-join(($seq, $in), '')"/> </xsl:otherwise> </xsl:choose> </xsl:when> <xsl:when test="contains($in, '%')"> <xsl:variable name="s" as="xs:string" select="substring-before($in, '%')"/> <xsl:sequence select="sf:pct-decode(substring($in, string-length($s)+1), ($seq, $s))"/> </xsl:when> <xsl:otherwise > <xsl:sequence select="string-join(($seq, $in), '')"/> </xsl:otherwise> </xsl:choose> </xsl:function>