| 1 |
<?xml version="1.0" encoding="UTF-8"?> |
|---|
| 2 |
<!-- |
|---|
| 3 |
Licensed to Jasig under one or more contributor license |
|---|
| 4 |
agreements. See the NOTICE file distributed with this work |
|---|
| 5 |
for additional information regarding copyright ownership. |
|---|
| 6 |
Jasig licenses this file to you under the Apache License, |
|---|
| 7 |
Version 2.0 (the "License"); you may not use this file |
|---|
| 8 |
except in compliance with the License. You may obtain a |
|---|
| 9 |
copy of the License at: |
|---|
| 10 |
|
|---|
| 11 |
http://www.apache.org/licenses/LICENSE-2.0 |
|---|
| 12 |
|
|---|
| 13 |
Unless required by applicable law or agreed to in writing, |
|---|
| 14 |
software distributed under the License is distributed on |
|---|
| 15 |
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|---|
| 16 |
KIND, either express or implied. See the License for the |
|---|
| 17 |
specific language governing permissions and limitations |
|---|
| 18 |
under the License. |
|---|
| 19 |
--> |
|---|
| 20 |
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> |
|---|
| 21 |
|
|---|
| 22 |
<!-- UTILITY TEMPLATES --> |
|---|
| 23 |
|
|---|
| 24 |
<xsl:template name="escapeApos"> |
|---|
| 25 |
<xsl:param name="str"/> |
|---|
| 26 |
<xsl:variable name="apos" select='"'"'/> |
|---|
| 27 |
<xsl:choose> |
|---|
| 28 |
<xsl:when test="contains($str, $apos)"> |
|---|
| 29 |
<xsl:value-of select="substring-before($str, $apos)" /> |
|---|
| 30 |
<xsl:text>\'</xsl:text> |
|---|
| 31 |
<xsl:call-template name="escapeApos"> |
|---|
| 32 |
<xsl:with-param name="str" select="substring-after($str, $apos)" /> |
|---|
| 33 |
</xsl:call-template> |
|---|
| 34 |
</xsl:when> |
|---|
| 35 |
<xsl:otherwise> |
|---|
| 36 |
<xsl:value-of select="$str" /> |
|---|
| 37 |
</xsl:otherwise> |
|---|
| 38 |
</xsl:choose> |
|---|
| 39 |
</xsl:template> |
|---|
| 40 |
|
|---|
| 41 |
<!-- escape line breaks and double quotes --> |
|---|
| 42 |
<xsl:template name="escapeJson"> |
|---|
| 43 |
<xsl:param name="string"/> |
|---|
| 44 |
<xsl:call-template name="replace"> |
|---|
| 45 |
<xsl:with-param name="string"> |
|---|
| 46 |
<xsl:call-template name="replace"> |
|---|
| 47 |
<xsl:with-param name="string" select="$string"/> |
|---|
| 48 |
<xsl:with-param name="pattern" select="'
'"/> |
|---|
| 49 |
<xsl:with-param name="replacement" select="'\n'"/> |
|---|
| 50 |
</xsl:call-template> |
|---|
| 51 |
</xsl:with-param> |
|---|
| 52 |
<xsl:with-param name="pattern" select="'"'"/> |
|---|
| 53 |
<xsl:with-param name="replacement" select="'\"'"/> |
|---|
| 54 |
</xsl:call-template> |
|---|
| 55 |
</xsl:template> |
|---|
| 56 |
|
|---|
| 57 |
<xsl:template name="httpStatusCodes"> |
|---|
| 58 |
<xsl:param name="code"/> |
|---|
| 59 |
<xsl:value-of select="$code"/><xsl:text>: </xsl:text> |
|---|
| 60 |
<xsl:choose> |
|---|
| 61 |
<xsl:when test="node() = 100">Continue</xsl:when> |
|---|
| 62 |
<xsl:when test="node() = 101">Switching Protocols</xsl:when> |
|---|
| 63 |
<xsl:when test="node() = 200">OK</xsl:when> |
|---|
| 64 |
<xsl:when test="node() = 201">Created</xsl:when> |
|---|
| 65 |
<xsl:when test="node() = 202">Accepted</xsl:when> |
|---|
| 66 |
<xsl:when test="node() = 203">Non-Authoritative Information</xsl:when> |
|---|
| 67 |
<xsl:when test="node() = 204">No Content</xsl:when> |
|---|
| 68 |
<xsl:when test="node() = 205">Reset Content</xsl:when> |
|---|
| 69 |
<xsl:when test="node() = 206">Partial Content</xsl:when> |
|---|
| 70 |
<xsl:when test="node() = 300">Multiple Choices</xsl:when> |
|---|
| 71 |
<xsl:when test="node() = 301">Moved Permanently</xsl:when> |
|---|
| 72 |
<xsl:when test="node() = 302">Found</xsl:when> |
|---|
| 73 |
<xsl:when test="node() = 303">See Other</xsl:when> |
|---|
| 74 |
<xsl:when test="node() = 304">Not Modified</xsl:when> |
|---|
| 75 |
<xsl:when test="node() = 305">Use Proxy</xsl:when> |
|---|
| 76 |
<xsl:when test="node() = 307">Temporary Redirect</xsl:when> |
|---|
| 77 |
<xsl:when test="node() = 400">Bad Request</xsl:when> |
|---|
| 78 |
<xsl:when test="node() = 401">Unauthorized</xsl:when> |
|---|
| 79 |
<xsl:when test="node() = 402">Payment Required</xsl:when> |
|---|
| 80 |
<xsl:when test="node() = 403">Forbidden</xsl:when> |
|---|
| 81 |
<xsl:when test="node() = 404">Not Found</xsl:when> |
|---|
| 82 |
<xsl:when test="node() = 405">Method Not Allowed</xsl:when> |
|---|
| 83 |
<xsl:when test="node() = 406">Not Acceptable</xsl:when> |
|---|
| 84 |
<xsl:when test="node() = 407">Proxy Authentication Required</xsl:when> |
|---|
| 85 |
<xsl:when test="node() = 408">Request Timeout</xsl:when> |
|---|
| 86 |
<xsl:when test="node() = 409">Conflict</xsl:when> |
|---|
| 87 |
<xsl:when test="node() = 410">Gone</xsl:when> |
|---|
| 88 |
<xsl:when test="node() = 411">Length Required</xsl:when> |
|---|
| 89 |
<xsl:when test="node() = 412">Precondition Failed</xsl:when> |
|---|
| 90 |
<xsl:when test="node() = 413">Request Entity Too Large</xsl:when> |
|---|
| 91 |
<xsl:when test="node() = 414">Request-URI Too Long</xsl:when> |
|---|
| 92 |
<xsl:when test="node() = 415">Unsupported Media Type</xsl:when> |
|---|
| 93 |
<xsl:when test="node() = 416">Requested Range Not Satisfiable</xsl:when> |
|---|
| 94 |
<xsl:when test="node() = 417">Expectation Failed</xsl:when> |
|---|
| 95 |
<xsl:when test="node() = 500">Internal Server Error</xsl:when> |
|---|
| 96 |
<xsl:when test="node() = 501">Not Implemented</xsl:when> |
|---|
| 97 |
<xsl:when test="node() = 502">Bad Gateway</xsl:when> |
|---|
| 98 |
<xsl:when test="node() = 503">Service Unavailable</xsl:when> |
|---|
| 99 |
<xsl:when test="node() = 504">Gateway Timeout</xsl:when> |
|---|
| 100 |
<xsl:when test="node() = 505">HTTP Version Not Supported</xsl:when> |
|---|
| 101 |
</xsl:choose> |
|---|
| 102 |
</xsl:template> |
|---|
| 103 |
|
|---|
| 104 |
<!-- search and replace template taken from |
|---|
| 105 |
http://www.biglist.com/lists/xsl-list/archives/200211/msg00337.html --> |
|---|
| 106 |
<xsl:template name="replace"> |
|---|
| 107 |
<xsl:param name="string" select="''"/> |
|---|
| 108 |
<xsl:param name="pattern" select="''"/> |
|---|
| 109 |
<xsl:param name="replacement" select="''"/> |
|---|
| 110 |
<xsl:choose> |
|---|
| 111 |
<xsl:when test="$pattern != '' and $string != '' and contains($string, $pattern)"> |
|---|
| 112 |
<xsl:value-of select="substring-before($string, $pattern)"/> |
|---|
| 113 |
<xsl:copy-of select="$replacement"/> |
|---|
| 114 |
<xsl:call-template name="replace"> |
|---|
| 115 |
<xsl:with-param name="string" select="substring-after($string, $pattern)"/> |
|---|
| 116 |
<xsl:with-param name="pattern" select="$pattern"/> |
|---|
| 117 |
<xsl:with-param name="replacement" select="$replacement"/> |
|---|
| 118 |
</xsl:call-template> |
|---|
| 119 |
</xsl:when> |
|---|
| 120 |
<xsl:otherwise> |
|---|
| 121 |
<xsl:value-of select="$string"/> |
|---|
| 122 |
</xsl:otherwise> |
|---|
| 123 |
</xsl:choose> |
|---|
| 124 |
</xsl:template> |
|---|
| 125 |
|
|---|
| 126 |
<!-- URL-encoding template Written by Mike J. Brown, mike@skew.org. |
|---|
| 127 |
No license; use freely, but credit me if reproducing in print. |
|---|
| 128 |
http://skew.org/xml/stylesheets/url-encode/ --> |
|---|
| 129 |
<xsl:template name="url-encode"> |
|---|
| 130 |
<xsl:param name="str"/> |
|---|
| 131 |
|
|---|
| 132 |
<!-- Characters we'll support. We could add control chars 0-31 and 127-159, but we won't. --> |
|---|
| 133 |
<xsl:variable name="ascii"> !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~</xsl:variable> |
|---|
| 134 |
<xsl:variable name="latin1"> ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ</xsl:variable> |
|---|
| 135 |
|
|---|
| 136 |
<!-- Characters that usually don't need to be escaped --> |
|---|
| 137 |
<xsl:variable name="safe">!'()*-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~</xsl:variable> |
|---|
| 138 |
|
|---|
| 139 |
<xsl:variable name="hex">0123456789ABCDEF</xsl:variable> |
|---|
| 140 |
|
|---|
| 141 |
<xsl:if test="$str"> |
|---|
| 142 |
<xsl:variable name="first-char" select="substring($str,1,1)"/> |
|---|
| 143 |
<xsl:choose> |
|---|
| 144 |
<xsl:when test="contains($safe,$first-char)"> |
|---|
| 145 |
<xsl:value-of select="$first-char"/> |
|---|
| 146 |
</xsl:when> |
|---|
| 147 |
<xsl:otherwise> |
|---|
| 148 |
<xsl:variable name="codepoint"> |
|---|
| 149 |
<xsl:choose> |
|---|
| 150 |
<xsl:when test="contains($ascii,$first-char)"> |
|---|
| 151 |
<xsl:value-of select="string-length(substring-before($ascii,$first-char)) + 32"/> |
|---|
| 152 |
</xsl:when> |
|---|
| 153 |
<xsl:when test="contains($latin1,$first-char)"> |
|---|
| 154 |
<xsl:value-of select="string-length(substring-before($latin1,$first-char)) + 160"/> |
|---|
| 155 |
</xsl:when> |
|---|
| 156 |
<xsl:otherwise> |
|---|
| 157 |
<xsl:message terminate="no">Warning: string contains a character that is out of range! Substituting "?".</xsl:message> |
|---|
| 158 |
<xsl:text>63</xsl:text> |
|---|
| 159 |
</xsl:otherwise> |
|---|
| 160 |
</xsl:choose> |
|---|
| 161 |
</xsl:variable> |
|---|
| 162 |
<xsl:variable name="hex-digit1" select="substring($hex,floor($codepoint div 16) + 1,1)"/> |
|---|
| 163 |
<xsl:variable name="hex-digit2" select="substring($hex,$codepoint mod 16 + 1,1)"/> |
|---|
| 164 |
<xsl:value-of select="concat('%',$hex-digit1,$hex-digit2)"/> |
|---|
| 165 |
</xsl:otherwise> |
|---|
| 166 |
</xsl:choose> |
|---|
| 167 |
<xsl:if test="string-length($str) > 1"> |
|---|
| 168 |
<xsl:call-template name="url-encode"> |
|---|
| 169 |
<xsl:with-param name="str" select="substring($str,2)"/> |
|---|
| 170 |
</xsl:call-template> |
|---|
| 171 |
</xsl:if> |
|---|
| 172 |
</xsl:if> |
|---|
| 173 |
</xsl:template> |
|---|
| 174 |
|
|---|
| 175 |
<xsl:template name="substring-afterLastInstanceOf"> |
|---|
| 176 |
<xsl:param name="string" /> |
|---|
| 177 |
<xsl:param name="char" /> |
|---|
| 178 |
<xsl:choose> |
|---|
| 179 |
<xsl:when test="contains($string, $char)"> |
|---|
| 180 |
<xsl:call-template name="substring-afterLastInstanceOf"> |
|---|
| 181 |
<xsl:with-param name="string" select="substring-after($string, $char)" /> |
|---|
| 182 |
<xsl:with-param name="char" select="$char" /> |
|---|
| 183 |
</xsl:call-template> |
|---|
| 184 |
</xsl:when> |
|---|
| 185 |
<xsl:otherwise><xsl:value-of select="$string" /></xsl:otherwise> |
|---|
| 186 |
</xsl:choose> |
|---|
| 187 |
</xsl:template> |
|---|
| 188 |
|
|---|
| 189 |
</xsl:stylesheet> |
|---|
| 190 |
|
|---|