paulb@233 | 1 | <?xml version="1.0"?> |
paulb@274 | 2 | <!-- |
paulb@274 | 3 | Copyright (C) 2005 Paul Boddie <paul@boddie.org.uk> |
paulb@274 | 4 | |
paulb@274 | 5 | This library is free software; you can redistribute it and/or |
paulb@274 | 6 | modify it under the terms of the GNU Lesser General Public |
paulb@274 | 7 | License as published by the Free Software Foundation; either |
paulb@274 | 8 | version 2.1 of the License, or (at your option) any later version. |
paulb@274 | 9 | |
paulb@274 | 10 | This library is distributed in the hope that it will be useful, |
paulb@274 | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
paulb@274 | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
paulb@274 | 13 | Lesser General Public License for more details. |
paulb@274 | 14 | |
paulb@274 | 15 | You should have received a copy of the GNU Lesser General Public |
paulb@274 | 16 | License along with this library; if not, write to the Free Software |
paulb@412 | 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
paulb@274 | 18 | --> |
paulb@233 | 19 | <xsl:stylesheet version="1.0" |
paulb@233 | 20 | xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
paulb@233 | 21 | xmlns:template="http://www.boddie.org.uk/ns/xmltools/template"> |
paulb@233 | 22 | |
paulb@233 | 23 | <xsl:output indent="yes"/> |
paulb@233 | 24 | |
paulb@233 | 25 | |
paulb@233 | 26 | |
paulb@233 | 27 | <!-- Match the document itself. --> |
paulb@233 | 28 | |
paulb@233 | 29 | <xsl:template match="/"> |
paulb@233 | 30 | <!-- Process the elements. --> |
paulb@233 | 31 | <xsl:apply-templates select="*"/> |
paulb@233 | 32 | </xsl:template> |
paulb@233 | 33 | |
paulb@233 | 34 | |
paulb@233 | 35 | |
paulb@233 | 36 | <!-- Match element references. --> |
paulb@233 | 37 | |
paulb@233 | 38 | <xsl:template match="*[@template:element]"> |
paulb@233 | 39 | <xsl:call-template name="enter-element"> |
paulb@233 | 40 | <xsl:with-param name="other-elements" select="@template:element"/> |
paulb@284 | 41 | <xsl:with-param name="other-init" select="@template:init"/> |
paulb@233 | 42 | </xsl:call-template> |
paulb@233 | 43 | </xsl:template> |
paulb@233 | 44 | |
paulb@233 | 45 | <xsl:template name="enter-element"> |
paulb@233 | 46 | <xsl:param name="other-elements"/> |
paulb@284 | 47 | <xsl:param name="other-init"/> |
paulb@233 | 48 | <xsl:variable name="first-element" select="substring-before($other-elements, ',')"/> |
paulb@233 | 49 | <xsl:variable name="remaining-elements" select="substring-after($other-elements, ',')"/> |
paulb@284 | 50 | <xsl:variable name="first-init" select="substring-before($other-init, ',')"/> |
paulb@284 | 51 | <xsl:variable name="remaining-init" select="substring-after($other-init, ',')"/> |
paulb@233 | 52 | <xsl:choose> |
paulb@233 | 53 | <xsl:when test="$first-element = ''"> |
paulb@233 | 54 | <xsl:call-template name="next-element"> |
paulb@233 | 55 | <xsl:with-param name="first-element" select="$other-elements"/> |
paulb@284 | 56 | <xsl:with-param name="first-init" select="$other-init"/> |
paulb@233 | 57 | </xsl:call-template> |
paulb@233 | 58 | </xsl:when> |
paulb@233 | 59 | <xsl:otherwise> |
paulb@233 | 60 | <xsl:call-template name="next-element"> |
paulb@233 | 61 | <xsl:with-param name="first-element" select="$first-element"/> |
paulb@233 | 62 | <xsl:with-param name="remaining-elements" select="$remaining-elements"/> |
paulb@284 | 63 | <xsl:with-param name="first-init" select="$first-init"/> |
paulb@284 | 64 | <xsl:with-param name="remaining-init" select="$remaining-init"/> |
paulb@233 | 65 | </xsl:call-template> |
paulb@233 | 66 | </xsl:otherwise> |
paulb@233 | 67 | </xsl:choose> |
paulb@233 | 68 | </xsl:template> |
paulb@233 | 69 | |
paulb@233 | 70 | <xsl:template name="next-element"> |
paulb@233 | 71 | <xsl:param name="first-element"/> |
paulb@233 | 72 | <xsl:param name="remaining-elements"/> |
paulb@284 | 73 | <xsl:param name="first-init"/> |
paulb@284 | 74 | <xsl:param name="remaining-init"/> |
paulb@245 | 75 | <element> |
paulb@233 | 76 | <xsl:attribute name="name"><xsl:value-of select="$first-element"/></xsl:attribute> |
paulb@284 | 77 | <xsl:if test="$first-init != ''"> |
paulb@284 | 78 | <xsl:attribute name="init"><xsl:value-of select="$first-init"/></xsl:attribute> |
paulb@284 | 79 | </xsl:if> |
paulb@233 | 80 | <xsl:choose> |
paulb@233 | 81 | <xsl:when test="$remaining-elements = ''"> |
paulb@233 | 82 | <xsl:call-template name="enter-attribute"/> |
paulb@233 | 83 | </xsl:when> |
paulb@233 | 84 | <xsl:otherwise> |
paulb@233 | 85 | <xsl:call-template name="enter-element"> |
paulb@233 | 86 | <xsl:with-param name="other-elements" select="$remaining-elements"/> |
paulb@284 | 87 | <xsl:with-param name="other-init" select="$remaining-init"/> |
paulb@233 | 88 | </xsl:call-template> |
paulb@233 | 89 | </xsl:otherwise> |
paulb@233 | 90 | </xsl:choose> |
paulb@245 | 91 | </element> |
paulb@233 | 92 | </xsl:template> |
paulb@233 | 93 | |
paulb@233 | 94 | |
paulb@233 | 95 | |
paulb@233 | 96 | <!-- Match attributes. --> |
paulb@233 | 97 | |
paulb@281 | 98 | <xsl:template match="*[not(@template:element) and (@template:attribute or @template:attribute-field or @template:attribute-area or @template:attribute-button or @template:attribute-list-button or @template:selector-field or @template:multiple-choice-field or @template:multiple-choice-list-field or @template:multiple-choice-value or @template:multiple-choice-list-value) or @template:multiple-choice-list-element]"> |
paulb@233 | 99 | <xsl:call-template name="enter-attribute"/> |
paulb@233 | 100 | </xsl:template> |
paulb@233 | 101 | |
paulb@233 | 102 | <xsl:template name="enter-attribute"> |
paulb@233 | 103 | <xsl:choose> |
paulb@233 | 104 | <xsl:when test="@template:attribute"> |
paulb@245 | 105 | <attribute> |
paulb@233 | 106 | <xsl:attribute name="name"><xsl:value-of select="@template:attribute"/></xsl:attribute> |
paulb@245 | 107 | </attribute> |
paulb@233 | 108 | </xsl:when> |
paulb@258 | 109 | <xsl:when test="@template:attribute-field"> |
paulb@258 | 110 | <attribute> |
paulb@258 | 111 | <xsl:attribute name="name"><xsl:value-of select="@template:attribute-field"/></xsl:attribute> |
paulb@258 | 112 | </attribute> |
paulb@258 | 113 | </xsl:when> |
paulb@258 | 114 | <xsl:when test="@template:attribute-area"> |
paulb@258 | 115 | <attribute> |
paulb@281 | 116 | <xsl:variable name="field-attr" select="substring-before(@template:attribute-area, ',')"/> |
paulb@281 | 117 | <xsl:choose> |
paulb@281 | 118 | <xsl:when test="$field-attr != ''"> |
paulb@281 | 119 | <xsl:attribute name="name"><xsl:value-of select="$field-attr"/></xsl:attribute> |
paulb@281 | 120 | </xsl:when> |
paulb@281 | 121 | <xsl:otherwise> |
paulb@281 | 122 | <xsl:attribute name="name"><xsl:value-of select="@template:attribute-area"/></xsl:attribute> |
paulb@281 | 123 | </xsl:otherwise> |
paulb@281 | 124 | </xsl:choose> |
paulb@258 | 125 | </attribute> |
paulb@258 | 126 | </xsl:when> |
paulb@258 | 127 | <xsl:when test="@template:attribute-button"> |
paulb@258 | 128 | <attribute> |
paulb@258 | 129 | <xsl:variable name="field-attr" select="substring-before(@template:attribute-button, ',')"/> |
paulb@258 | 130 | <xsl:attribute name="name"><xsl:value-of select="$field-attr"/></xsl:attribute> |
paulb@258 | 131 | </attribute> |
paulb@258 | 132 | </xsl:when> |
paulb@281 | 133 | <xsl:when test="@template:attribute-list-button"> |
paulb@281 | 134 | <attribute> |
paulb@281 | 135 | <xsl:variable name="field-attr" select="substring-before(@template:attribute-list-button, ',')"/> |
paulb@281 | 136 | <xsl:attribute name="name"><xsl:value-of select="$field-attr"/></xsl:attribute> |
paulb@281 | 137 | </attribute> |
paulb@281 | 138 | </xsl:when> |
paulb@258 | 139 | <xsl:when test="@template:selector-field"> |
paulb@258 | 140 | <xsl:variable name="field-name" select="substring-before(@template:selector-field, ',')"/> |
paulb@258 | 141 | <xsl:variable name="affected-element" select="substring-after(@template:selector-field, ',')"/> |
paulb@258 | 142 | <selector> |
paulb@258 | 143 | <xsl:choose> |
paulb@258 | 144 | <xsl:when test="$field-name != ''"> |
paulb@258 | 145 | <xsl:attribute name="name"><xsl:value-of select="$field-name"/></xsl:attribute> |
paulb@258 | 146 | <xsl:attribute name="element"><xsl:value-of select="$affected-element"/></xsl:attribute> |
paulb@258 | 147 | </xsl:when> |
paulb@258 | 148 | <xsl:otherwise> |
paulb@258 | 149 | <xsl:attribute name="name"><xsl:value-of select="@template:selector-field"/></xsl:attribute> |
paulb@258 | 150 | </xsl:otherwise> |
paulb@258 | 151 | </xsl:choose> |
paulb@258 | 152 | </selector> |
paulb@258 | 153 | </xsl:when> |
paulb@258 | 154 | <xsl:when test="@template:multiple-choice-field"> |
paulb@262 | 155 | <xsl:variable name="field-element" select="substring-before(@template:multiple-choice-field, ',')"/> |
paulb@282 | 156 | <xsl:variable name="field-attr-info" select="substring-after(@template:multiple-choice-field, ',')"/> |
paulb@282 | 157 | <xsl:variable name="field-attr" select="substring-before($field-attr-info, ',')"/> |
paulb@466 | 158 | <xsl:variable name="field-attr-type-info" select="substring-after($field-attr-info, ',')"/> |
paulb@466 | 159 | <xsl:variable name="field-attr-type" select="substring-before($field-attr-type-info, ',')"/> |
paulb@466 | 160 | <xsl:variable name="field-source-type" select="substring-after($field-attr-type-info, ',')"/> |
paulb@262 | 161 | <xsl:choose> |
paulb@262 | 162 | <xsl:when test="$field-element != '-'"> |
paulb@262 | 163 | <element type="multiple-choice"> |
paulb@262 | 164 | <xsl:attribute name="name"><xsl:value-of select="$field-element"/></xsl:attribute> |
paulb@466 | 165 | <xsl:if test="$field-source-type = 'dynamic'"> |
paulb@466 | 166 | <xsl:attribute name="source">dynamic</xsl:attribute> |
paulb@466 | 167 | </xsl:if> |
paulb@262 | 168 | <attribute> |
paulb@282 | 169 | <xsl:choose> |
paulb@282 | 170 | <xsl:when test="$field-attr != ''"> |
paulb@282 | 171 | <xsl:attribute name="name"><xsl:value-of select="$field-attr"/></xsl:attribute> |
paulb@282 | 172 | </xsl:when> |
paulb@282 | 173 | <xsl:otherwise> |
paulb@282 | 174 | <xsl:attribute name="name"><xsl:value-of select="$field-attr-info"/></xsl:attribute> |
paulb@282 | 175 | </xsl:otherwise> |
paulb@282 | 176 | </xsl:choose> |
paulb@262 | 177 | </attribute> |
paulb@262 | 178 | <xsl:apply-templates select="*"/> |
paulb@262 | 179 | </element> |
paulb@262 | 180 | </xsl:when> |
paulb@262 | 181 | <xsl:otherwise> |
paulb@262 | 182 | <xsl:attribute name="type">multiple-choice</xsl:attribute> |
paulb@466 | 183 | <xsl:if test="$field-source-type = 'dynamic'"> |
paulb@466 | 184 | <xsl:attribute name="source">dynamic</xsl:attribute> |
paulb@466 | 185 | </xsl:if> |
paulb@262 | 186 | <attribute> |
paulb@282 | 187 | <xsl:choose> |
paulb@282 | 188 | <xsl:when test="$field-attr != ''"> |
paulb@282 | 189 | <xsl:attribute name="name"><xsl:value-of select="$field-attr"/></xsl:attribute> |
paulb@282 | 190 | </xsl:when> |
paulb@282 | 191 | <xsl:otherwise> |
paulb@282 | 192 | <xsl:attribute name="name"><xsl:value-of select="$field-attr-info"/></xsl:attribute> |
paulb@282 | 193 | </xsl:otherwise> |
paulb@282 | 194 | </xsl:choose> |
paulb@262 | 195 | </attribute> |
paulb@262 | 196 | <xsl:apply-templates select="*"/> |
paulb@262 | 197 | </xsl:otherwise> |
paulb@262 | 198 | </xsl:choose> |
paulb@258 | 199 | </xsl:when> |
paulb@258 | 200 | <xsl:when test="@template:multiple-choice-list-field"> |
paulb@262 | 201 | <xsl:variable name="field-element" select="substring-before(@template:multiple-choice-list-field, ',')"/> |
paulb@262 | 202 | <xsl:variable name="field-list-info" select="substring-after(@template:multiple-choice-list-field, ',')"/> |
paulb@262 | 203 | <xsl:variable name="field-list-element" select="substring-before($field-list-info, ',')"/> |
paulb@466 | 204 | <xsl:variable name="field-list-attr-info" select="substring-after($field-list-info, ',')"/> |
paulb@466 | 205 | <xsl:variable name="field-list-attr" select="substring-before($field-list-attr-info, ',')"/> |
paulb@466 | 206 | <xsl:variable name="field-source-type" select="substring-after($field-list-attr-info, ',')"/> |
paulb@262 | 207 | <xsl:choose> |
paulb@262 | 208 | <xsl:when test="$field-element != '-'"> |
paulb@262 | 209 | <element type="multiple-choice-list"> |
paulb@262 | 210 | <xsl:attribute name="name"><xsl:value-of select="$field-element"/></xsl:attribute> |
paulb@466 | 211 | <xsl:if test="$field-source-type = 'dynamic'"> |
paulb@466 | 212 | <xsl:attribute name="source">dynamic</xsl:attribute> |
paulb@466 | 213 | </xsl:if> |
paulb@262 | 214 | <attribute> |
paulb@262 | 215 | <xsl:attribute name="name"><xsl:value-of select="$field-list-attr"/></xsl:attribute> |
paulb@262 | 216 | </attribute> |
paulb@262 | 217 | <xsl:apply-templates select="*"/> |
paulb@262 | 218 | </element> |
paulb@262 | 219 | </xsl:when> |
paulb@262 | 220 | <xsl:otherwise> |
paulb@262 | 221 | <xsl:attribute name="type">multiple-choice-list</xsl:attribute> |
paulb@466 | 222 | <xsl:if test="$field-source-type = 'dynamic'"> |
paulb@466 | 223 | <xsl:attribute name="source">dynamic</xsl:attribute> |
paulb@466 | 224 | </xsl:if> |
paulb@262 | 225 | <attribute> |
paulb@262 | 226 | <xsl:attribute name="name"><xsl:value-of select="$field-list-attr"/></xsl:attribute> |
paulb@262 | 227 | </attribute> |
paulb@262 | 228 | <xsl:apply-templates select="*"/> |
paulb@262 | 229 | </xsl:otherwise> |
paulb@262 | 230 | </xsl:choose> |
paulb@258 | 231 | </xsl:when> |
paulb@281 | 232 | <xsl:when test="@template:multiple-choice-list-element"> |
paulb@281 | 233 | <xsl:variable name="element" select="substring-before(@template:multiple-choice-list-element, ',')"/> |
paulb@281 | 234 | <xsl:variable name="element-list-info" select="substring-after(@template:multiple-choice-list-element, ',')"/> |
paulb@281 | 235 | <xsl:variable name="element-list-element" select="substring-before($element-list-info, ',')"/> |
paulb@281 | 236 | <xsl:variable name="element-list-attr" select="substring-after($element-list-info, ',')"/> |
paulb@281 | 237 | <xsl:choose> |
paulb@281 | 238 | <xsl:when test="$element != '-'"> |
paulb@281 | 239 | <element type="multiple-choice-list"> |
paulb@281 | 240 | <xsl:attribute name="name"><xsl:value-of select="$element"/></xsl:attribute> |
paulb@281 | 241 | <element type="multiple-choice-list-value"> |
paulb@281 | 242 | <xsl:attribute name="name"><xsl:value-of select="$element-list-element"/></xsl:attribute> |
paulb@281 | 243 | <xsl:attribute name="expr-name">value-is-set</xsl:attribute> |
paulb@281 | 244 | <xsl:apply-templates select="*"/> |
paulb@281 | 245 | </element> |
paulb@281 | 246 | </element> |
paulb@281 | 247 | </xsl:when> |
paulb@281 | 248 | <xsl:otherwise> |
paulb@281 | 249 | <xsl:attribute name="type">multiple-choice-list</xsl:attribute> |
paulb@281 | 250 | <element type="multiple-choice-list-value"> |
paulb@281 | 251 | <xsl:attribute name="name"><xsl:value-of select="$element-list-element"/></xsl:attribute> |
paulb@281 | 252 | <xsl:attribute name="expr-name">value-is-set</xsl:attribute> |
paulb@281 | 253 | <xsl:apply-templates select="*"/> |
paulb@281 | 254 | </element> |
paulb@281 | 255 | </xsl:otherwise> |
paulb@281 | 256 | </xsl:choose> |
paulb@281 | 257 | </xsl:when> |
paulb@258 | 258 | <xsl:when test="@template:multiple-choice-value"> |
paulb@258 | 259 | <element type="multiple-choice-value"> |
paulb@258 | 260 | <xsl:variable name="field-element" select="substring-before(@template:multiple-choice-value, ',')"/> |
paulb@258 | 261 | <xsl:variable name="field-attr-info" select="substring-after(@template:multiple-choice-value, ',')"/> |
paulb@258 | 262 | <xsl:variable name="field-attr" select="substring-before($field-attr-info, ',')"/> |
paulb@466 | 263 | <xsl:variable name="field-set-attr-info" select="substring-after($field-attr-info, ',')"/> |
paulb@466 | 264 | <xsl:variable name="field-set-attr" select="substring-before($field-set-attr-info, ',')"/> |
paulb@466 | 265 | <xsl:variable name="field-contents" select="substring-after($field-set-attr-info, ',')"/> |
paulb@258 | 266 | <xsl:attribute name="name"><xsl:value-of select="$field-element"/></xsl:attribute> |
paulb@258 | 267 | <xsl:attribute name="expr">@<xsl:value-of select="$field-attr"/> = ../@<xsl:value-of select="$field-attr"/></xsl:attribute> |
paulb@466 | 268 | <xsl:choose> |
paulb@466 | 269 | <xsl:when test="$field-set-attr != ''"> |
paulb@466 | 270 | <xsl:attribute name="expr-attr"><xsl:value-of select="$field-set-attr"/></xsl:attribute> |
paulb@466 | 271 | </xsl:when> |
paulb@466 | 272 | <xsl:otherwise> |
paulb@466 | 273 | <xsl:attribute name="expr-attr"><xsl:value-of select="$field-set-attr-info"/></xsl:attribute> |
paulb@466 | 274 | </xsl:otherwise> |
paulb@466 | 275 | </xsl:choose> |
paulb@258 | 276 | <attribute> |
paulb@258 | 277 | <xsl:attribute name="name"><xsl:value-of select="$field-attr"/></xsl:attribute> |
paulb@258 | 278 | </attribute> |
paulb@258 | 279 | </element> |
paulb@258 | 280 | </xsl:when> |
paulb@258 | 281 | <xsl:when test="@template:multiple-choice-list-value"> |
paulb@258 | 282 | <element type="multiple-choice-list-value"> |
paulb@258 | 283 | <xsl:variable name="field-element" select="substring-before(@template:multiple-choice-list-value, ',')"/> |
paulb@258 | 284 | <xsl:variable name="field-attr-info" select="substring-after(@template:multiple-choice-list-value, ',')"/> |
paulb@258 | 285 | <xsl:variable name="field-attr" select="substring-before($field-attr-info, ',')"/> |
paulb@466 | 286 | <xsl:variable name="field-set-attr-info" select="substring-after($field-attr-info, ',')"/> |
paulb@466 | 287 | <xsl:variable name="field-set-attr" select="substring-before($field-set-attr-info, ',')"/> |
paulb@466 | 288 | <xsl:variable name="field-contents" select="substring-after($field-set-attr-info, ',')"/> |
paulb@258 | 289 | <xsl:attribute name="name"><xsl:value-of select="$field-element"/></xsl:attribute> |
paulb@258 | 290 | <xsl:attribute name="expr">@value-is-set</xsl:attribute> |
paulb@258 | 291 | <!-- Special attribute corresponding with the expression. --> |
paulb@258 | 292 | <xsl:attribute name="expr-name">value-is-set</xsl:attribute> |
paulb@466 | 293 | <xsl:choose> |
paulb@466 | 294 | <xsl:when test="$field-set-attr != ''"> |
paulb@466 | 295 | <xsl:attribute name="expr-attr"><xsl:value-of select="$field-set-attr"/></xsl:attribute> |
paulb@466 | 296 | </xsl:when> |
paulb@466 | 297 | <xsl:otherwise> |
paulb@466 | 298 | <xsl:attribute name="expr-attr"><xsl:value-of select="$field-set-attr-info"/></xsl:attribute> |
paulb@466 | 299 | </xsl:otherwise> |
paulb@466 | 300 | </xsl:choose> |
paulb@258 | 301 | <attribute> |
paulb@258 | 302 | <xsl:attribute name="name"><xsl:value-of select="$field-attr"/></xsl:attribute> |
paulb@258 | 303 | </attribute> |
paulb@258 | 304 | </element> |
paulb@258 | 305 | </xsl:when> |
paulb@233 | 306 | <xsl:otherwise> |
paulb@233 | 307 | <xsl:apply-templates select="*"/> |
paulb@233 | 308 | </xsl:otherwise> |
paulb@233 | 309 | </xsl:choose> |
paulb@233 | 310 | </xsl:template> |
paulb@233 | 311 | |
paulb@233 | 312 | |
paulb@233 | 313 | |
paulb@233 | 314 | <!-- Traverse unknown elements. --> |
paulb@233 | 315 | |
paulb@233 | 316 | <xsl:template match="*"> |
paulb@233 | 317 | <xsl:apply-templates select="*"/> |
paulb@233 | 318 | </xsl:template> |
paulb@233 | 319 | |
paulb@233 | 320 | </xsl:stylesheet> |