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