1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
<?xml version="1.0" encoding="utf-8"?>
<!-- Obtained from http://skew.org/xml/stylesheets/url-encode/url-decode.xsl -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" indent="no" encoding="iso-8859-1"/>
<!-- <xsl:param name="url" select="'urn:check%20out%20my%20r%E9sum%E9'"/>-->
<xsl:variable name="hex" select="'0123456789ABCDEF'"/>
<xsl:variable name="ascii"> !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~</xsl:variable>
<xsl:variable name="latin1"> ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ</xsl:variable>
<!-- <xsl:template match="/">
<xsl:call-template name="decode">
<xsl:with-param name="encoded" select="$url"/>
</xsl:call-template>
</xsl:template> -->
<xsl:template name="decode">
<xsl:param name="encoded"/>
<xsl:choose>
<xsl:when test="contains($encoded,'%')">
<xsl:value-of select="substring-before($encoded,'%')"/>
<xsl:variable name="hexpair" select="translate(substring(substring-after($encoded,'%'),1,2),'abcdef','ABCDEF')"/>
<xsl:variable name="decimal" select="(string-length(substring-before($hex,substring($hexpair,1,1))))*16 + string-length(substring-before($hex,substring($hexpair,2,1)))"/>
<xsl:choose>
<xsl:when test="$decimal < 127 and $decimal > 31">
<xsl:value-of select="substring($ascii,$decimal - 31,1)"/>
</xsl:when>
<xsl:when test="$decimal > 159">
<xsl:value-of select="substring($latin1,$decimal - 159,1)"/>
</xsl:when>
<xsl:otherwise>?</xsl:otherwise>
</xsl:choose>
<xsl:call-template name="decode">
<xsl:with-param name="encoded" select="substring(substring-after($encoded,'%'),3)"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$encoded"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
|