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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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:call-template> 42 </xsl:template> 43 44 <xsl:template name="enter-element"> 45 <xsl:param name="other-elements"/> 46 <xsl:variable name="first-element" select="substring-before($other-elements, ',')"/> 47 <xsl:variable name="remaining-elements" select="substring-after($other-elements, ',')"/> 48 <xsl:choose> 49 <xsl:when test="$first-element = ''"> 50 <xsl:call-template name="next-element"> 51 <xsl:with-param name="first-element" select="$other-elements"/> 52 </xsl:call-template> 53 </xsl:when> 54 <xsl:otherwise> 55 <xsl:call-template name="next-element"> 56 <xsl:with-param name="first-element" select="$first-element"/> 57 <xsl:with-param name="remaining-elements" select="$remaining-elements"/> 58 </xsl:call-template> 59 </xsl:otherwise> 60 </xsl:choose> 61 </xsl:template> 62 63 <xsl:template name="next-element"> 64 <xsl:param name="first-element"/> 65 <xsl:param name="remaining-elements"/> 66 <element> 67 <xsl:attribute name="name"><xsl:value-of select="$first-element"/></xsl:attribute> 68 <xsl:choose> 69 <xsl:when test="$remaining-elements = ''"> 70 <xsl:call-template name="enter-attribute"/> 71 </xsl:when> 72 <xsl:otherwise> 73 <xsl:call-template name="enter-element"> 74 <xsl:with-param name="other-elements" select="$remaining-elements"/> 75 </xsl:call-template> 76 </xsl:otherwise> 77 </xsl:choose> 78 </element> 79 </xsl:template> 80 81 82 83 <!-- Match attributes. --> 84 85 <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]"> 86 <xsl:call-template name="enter-attribute"/> 87 </xsl:template> 88 89 <xsl:template name="enter-attribute"> 90 <xsl:choose> 91 <xsl:when test="@template:attribute"> 92 <attribute> 93 <xsl:attribute name="name"><xsl:value-of select="@template:attribute"/></xsl:attribute> 94 </attribute> 95 </xsl:when> 96 <xsl:when test="@template:attribute-field"> 97 <attribute> 98 <xsl:attribute name="name"><xsl:value-of select="@template:attribute-field"/></xsl:attribute> 99 </attribute> 100 </xsl:when> 101 <xsl:when test="@template:attribute-area"> 102 <attribute> 103 <xsl:variable name="field-attr" select="substring-before(@template:attribute-area, ',')"/> 104 <xsl:choose> 105 <xsl:when test="$field-attr != ''"> 106 <xsl:attribute name="name"><xsl:value-of select="$field-attr"/></xsl:attribute> 107 </xsl:when> 108 <xsl:otherwise> 109 <xsl:attribute name="name"><xsl:value-of select="@template:attribute-area"/></xsl:attribute> 110 </xsl:otherwise> 111 </xsl:choose> 112 </attribute> 113 </xsl:when> 114 <xsl:when test="@template:attribute-button"> 115 <attribute> 116 <xsl:variable name="field-attr" select="substring-before(@template:attribute-button, ',')"/> 117 <xsl:attribute name="name"><xsl:value-of select="$field-attr"/></xsl:attribute> 118 </attribute> 119 </xsl:when> 120 <xsl:when test="@template:attribute-list-button"> 121 <attribute> 122 <xsl:variable name="field-attr" select="substring-before(@template:attribute-list-button, ',')"/> 123 <xsl:attribute name="name"><xsl:value-of select="$field-attr"/></xsl:attribute> 124 </attribute> 125 </xsl:when> 126 <xsl:when test="@template:selector-field"> 127 <xsl:variable name="field-name" select="substring-before(@template:selector-field, ',')"/> 128 <xsl:variable name="affected-element" select="substring-after(@template:selector-field, ',')"/> 129 <selector> 130 <xsl:choose> 131 <xsl:when test="$field-name != ''"> 132 <xsl:attribute name="name"><xsl:value-of select="$field-name"/></xsl:attribute> 133 <xsl:attribute name="element"><xsl:value-of select="$affected-element"/></xsl:attribute> 134 </xsl:when> 135 <xsl:otherwise> 136 <xsl:attribute name="name"><xsl:value-of select="@template:selector-field"/></xsl:attribute> 137 </xsl:otherwise> 138 </xsl:choose> 139 </selector> 140 </xsl:when> 141 <xsl:when test="@template:multiple-choice-field"> 142 <xsl:variable name="field-element" select="substring-before(@template:multiple-choice-field, ',')"/> 143 <xsl:variable name="field-attr-info" select="substring-after(@template:multiple-choice-field, ',')"/> 144 <xsl:variable name="field-attr" select="substring-before($field-attr-info, ',')"/> 145 <xsl:variable name="field-attr-type" select="substring-after($field-attr-info, ',')"/> 146 <xsl:choose> 147 <xsl:when test="$field-element != '-'"> 148 <element type="multiple-choice"> 149 <xsl:attribute name="name"><xsl:value-of select="$field-element"/></xsl:attribute> 150 <attribute> 151 <xsl:choose> 152 <xsl:when test="$field-attr != ''"> 153 <xsl:attribute name="name"><xsl:value-of select="$field-attr"/></xsl:attribute> 154 </xsl:when> 155 <xsl:otherwise> 156 <xsl:attribute name="name"><xsl:value-of select="$field-attr-info"/></xsl:attribute> 157 </xsl:otherwise> 158 </xsl:choose> 159 </attribute> 160 <xsl:apply-templates select="*"/> 161 </element> 162 </xsl:when> 163 <xsl:otherwise> 164 <xsl:attribute name="type">multiple-choice</xsl:attribute> 165 <attribute> 166 <xsl:choose> 167 <xsl:when test="$field-attr != ''"> 168 <xsl:attribute name="name"><xsl:value-of select="$field-attr"/></xsl:attribute> 169 </xsl:when> 170 <xsl:otherwise> 171 <xsl:attribute name="name"><xsl:value-of select="$field-attr-info"/></xsl:attribute> 172 </xsl:otherwise> 173 </xsl:choose> 174 </attribute> 175 <xsl:apply-templates select="*"/> 176 </xsl:otherwise> 177 </xsl:choose> 178 </xsl:when> 179 <xsl:when test="@template:multiple-choice-list-field"> 180 <xsl:variable name="field-element" select="substring-before(@template:multiple-choice-list-field, ',')"/> 181 <xsl:variable name="field-list-info" select="substring-after(@template:multiple-choice-list-field, ',')"/> 182 <xsl:variable name="field-list-element" select="substring-before($field-list-info, ',')"/> 183 <xsl:variable name="field-list-attr" select="substring-after($field-list-info, ',')"/> 184 <xsl:choose> 185 <xsl:when test="$field-element != '-'"> 186 <element type="multiple-choice-list"> 187 <xsl:attribute name="name"><xsl:value-of select="$field-element"/></xsl:attribute> 188 <attribute> 189 <xsl:attribute name="name"><xsl:value-of select="$field-list-attr"/></xsl:attribute> 190 </attribute> 191 <xsl:apply-templates select="*"/> 192 </element> 193 </xsl:when> 194 <xsl:otherwise> 195 <xsl:attribute name="type">multiple-choice-list</xsl:attribute> 196 <attribute> 197 <xsl:attribute name="name"><xsl:value-of select="$field-list-attr"/></xsl:attribute> 198 </attribute> 199 <xsl:apply-templates select="*"/> 200 </xsl:otherwise> 201 </xsl:choose> 202 </xsl:when> 203 <xsl:when test="@template:multiple-choice-list-element"> 204 <xsl:variable name="element" select="substring-before(@template:multiple-choice-list-element, ',')"/> 205 <xsl:variable name="element-list-info" select="substring-after(@template:multiple-choice-list-element, ',')"/> 206 <xsl:variable name="element-list-element" select="substring-before($element-list-info, ',')"/> 207 <xsl:variable name="element-list-attr" select="substring-after($element-list-info, ',')"/> 208 <xsl:choose> 209 <xsl:when test="$element != '-'"> 210 <element type="multiple-choice-list"> 211 <xsl:attribute name="name"><xsl:value-of select="$element"/></xsl:attribute> 212 <element type="multiple-choice-list-value"> 213 <xsl:attribute name="name"><xsl:value-of select="$element-list-element"/></xsl:attribute> 214 <xsl:attribute name="expr-name">value-is-set</xsl:attribute> 215 <xsl:apply-templates select="*"/> 216 </element> 217 </element> 218 </xsl:when> 219 <xsl:otherwise> 220 <xsl:attribute name="type">multiple-choice-list</xsl:attribute> 221 <element type="multiple-choice-list-value"> 222 <xsl:attribute name="name"><xsl:value-of select="$element-list-element"/></xsl:attribute> 223 <xsl:attribute name="expr-name">value-is-set</xsl:attribute> 224 <xsl:apply-templates select="*"/> 225 </element> 226 </xsl:otherwise> 227 </xsl:choose> 228 </xsl:when> 229 <xsl:when test="@template:multiple-choice-value"> 230 <element type="multiple-choice-value"> 231 <xsl:variable name="field-element" select="substring-before(@template:multiple-choice-value, ',')"/> 232 <xsl:variable name="field-attr-info" select="substring-after(@template:multiple-choice-value, ',')"/> 233 <xsl:variable name="field-attr" select="substring-before($field-attr-info, ',')"/> 234 <xsl:variable name="field-set-attr" select="substring-after($field-attr-info, ',')"/> 235 <xsl:attribute name="name"><xsl:value-of select="$field-element"/></xsl:attribute> 236 <xsl:attribute name="expr">@<xsl:value-of select="$field-attr"/> = ../@<xsl:value-of select="$field-attr"/></xsl:attribute> 237 <xsl:attribute name="expr-attr"><xsl:value-of select="$field-set-attr"/></xsl:attribute> 238 <attribute> 239 <xsl:attribute name="name"><xsl:value-of select="$field-attr"/></xsl:attribute> 240 </attribute> 241 </element> 242 </xsl:when> 243 <xsl:when test="@template:multiple-choice-list-value"> 244 <element type="multiple-choice-list-value"> 245 <xsl:variable name="field-element" select="substring-before(@template:multiple-choice-list-value, ',')"/> 246 <xsl:variable name="field-attr-info" select="substring-after(@template:multiple-choice-list-value, ',')"/> 247 <xsl:variable name="field-attr" select="substring-before($field-attr-info, ',')"/> 248 <xsl:variable name="field-set-attr" select="substring-after($field-attr-info, ',')"/> 249 <xsl:attribute name="name"><xsl:value-of select="$field-element"/></xsl:attribute> 250 <xsl:attribute name="expr">@value-is-set</xsl:attribute> 251 <!-- Special attribute corresponding with the expression. --> 252 <xsl:attribute name="expr-name">value-is-set</xsl:attribute> 253 <xsl:attribute name="expr-attr"><xsl:value-of select="$field-set-attr"/></xsl:attribute> 254 <attribute> 255 <xsl:attribute name="name"><xsl:value-of select="$field-attr"/></xsl:attribute> 256 </attribute> 257 </element> 258 </xsl:when> 259 <xsl:otherwise> 260 <xsl:apply-templates select="*"/> 261 </xsl:otherwise> 262 </xsl:choose> 263 </xsl:template> 264 265 266 267 <!-- Traverse unknown elements. --> 268 269 <xsl:template match="*"> 270 <xsl:apply-templates select="*"/> 271 </xsl:template> 272 273 </xsl:stylesheet>