Decode an Encoded URI in Xslt 2.0

I have a URI which contains some encoded data:

I have extracted this data into a variable, however I cannot find a way to decode this data so that it can be processed within my XSLT 2.0 stylesheet. I have tried using the EXSLT str:decode-uri function, however it does not appear to be supported by Saxon.

The variable should read: "abc def"     and NOT "abc%20def"

Simply replacing all occurrences of %20 with a space is not an option. All codepoints need to be correctly decoded.

Is there a native way of achieving this in XSLT 2.0? If not what alternatives are there?
LVL 13
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

numberkruncherAuthor Commented:
I think that I have now solved the problem with the following source:
<!-- Function: doc:hex-to-dec -->
<!-- Description: Convert hexadecimal xs:string into xs:integer -->
<!-- Based on ref: -->
<xsl:function name="doc:hex-to-dec" as="xs:integer">
    <xsl:param name="hex" as="xs:string"/>
    <xsl:variable name="length" select="string-length($hex)" as="xs:integer"/>
    <xsl:value-of select="
        if ($length &gt; 0) then
            if ($length &lt; 2) then
                string-length(substring-before('0 1 2 3 4 5 6 7 8 9 AaBbCcDdEeFf',$hex)) idiv 2
                doc:hex-to-dec(substring($hex,1,$length - 1))*16+doc:hex-to-dec(substring($hex,$length))
<!-- Function: doc:decode-uri-component -->
<!-- Description: Decode URI component. -->
<xsl:function name="doc:decode-uri-component" as="xs:string">
    <xsl:param name="uri-component" as="xs:string"/>
    <xsl:variable name="decoded-component" as="xs:string*">
        <xsl:analyze-string select="$uri-component" regex="%(\d\d)">
                <xsl:value-of select="codepoints-to-string(doc:hex-to-dec(regex-group(1)))"/>
                <xsl:value-of select="."/>
    <xsl:value-of select="string-join($decoded-component,'')"/>

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.