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