| 8281 | | <!-- URL-encoding template Written by Mike J. Brown, mike@skew.org. |
|---|
| 8282 | | http://skew.org/xml/stylesheets/url-encode/ --> |
|---|
| 8283 | | <xsl:template name="url-encode"> |
|---|
| 8284 | | <xsl:param name="str"/> |
|---|
| 8285 | | |
|---|
| 8286 | | <!-- Characters we'll support. We could add control chars 0-31 and 127-159, but we won't. --> |
|---|
| 8287 | | <xsl:variable name="ascii"> !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~</xsl:variable> |
|---|
| 8288 | | <xsl:variable name="latin1"> ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ</xsl:variable> |
|---|
| 8289 | | |
|---|
| 8290 | | <!-- Characters that usually don't need to be escaped --> |
|---|
| 8291 | | <xsl:variable name="safe">!'()*-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~</xsl:variable> |
|---|
| 8292 | | |
|---|
| 8293 | | <xsl:variable name="hex">0123456789ABCDEF</xsl:variable> |
|---|
| 8294 | | |
|---|
| 8295 | | <xsl:if test="$str"> |
|---|
| 8296 | | <xsl:variable name="first-char" select="substring($str,1,1)"/> |
|---|
| 8297 | | <xsl:choose> |
|---|
| 8298 | | <xsl:when test="contains($safe,$first-char)"> |
|---|
| 8299 | | <xsl:value-of select="$first-char"/> |
|---|
| 8300 | | </xsl:when> |
|---|
| 8301 | | <xsl:otherwise> |
|---|
| 8302 | | <xsl:variable name="codepoint"> |
|---|
| 8303 | | <xsl:choose> |
|---|
| 8304 | | <xsl:when test="contains($ascii,$first-char)"> |
|---|
| 8305 | | <xsl:value-of select="string-length(substring-before($ascii,$first-char)) + 32"/> |
|---|
| 8306 | | </xsl:when> |
|---|
| 8307 | | <xsl:when test="contains($latin1,$first-char)"> |
|---|
| 8308 | | <xsl:value-of select="string-length(substring-before($latin1,$first-char)) + 160"/> |
|---|
| 8309 | | </xsl:when> |
|---|
| 8310 | | <xsl:otherwise> |
|---|
| 8311 | | <xsl:message terminate="no">Warning: string contains a character that is out of range! Substituting "?".</xsl:message> |
|---|
| 8312 | | <xsl:text>63</xsl:text> |
|---|
| 8313 | | </xsl:otherwise> |
|---|
| 8314 | | </xsl:choose> |
|---|
| 8315 | | </xsl:variable> |
|---|
| 8316 | | <xsl:variable name="hex-digit1" select="substring($hex,floor($codepoint div 16) + 1,1)"/> |
|---|
| 8317 | | <xsl:variable name="hex-digit2" select="substring($hex,$codepoint mod 16 + 1,1)"/> |
|---|
| 8318 | | <xsl:value-of select="concat('%',$hex-digit1,$hex-digit2)"/> |
|---|
| 8319 | | </xsl:otherwise> |
|---|
| 8320 | | </xsl:choose> |
|---|
| 8321 | | <xsl:if test="string-length($str) > 1"> |
|---|
| 8322 | | <xsl:call-template name="url-encode"> |
|---|
| 8323 | | <xsl:with-param name="str" select="substring($str,2)"/> |
|---|
| 8324 | | </xsl:call-template> |
|---|
| 8325 | | </xsl:if> |
|---|
| 8326 | | </xsl:if> |
|---|
| 8327 | | </xsl:template> |
|---|
| 8328 | | |
|---|