paulb@233 | 1 | <?xml version="1.0"?> |
paulb@274 | 2 | <!-- |
paulb@426 | 3 | A stylesheet which expands the higher-level macro attributes, producing |
paulb@426 | 4 | lower-level attributes that can be translated into the final output stylesheet |
paulb@426 | 5 | code. |
paulb@426 | 6 | |
paulb@274 | 7 | Copyright (C) 2005 Paul Boddie <paul@boddie.org.uk> |
paulb@274 | 8 | |
paulb@274 | 9 | This library is free software; you can redistribute it and/or |
paulb@274 | 10 | modify it under the terms of the GNU Lesser General Public |
paulb@274 | 11 | License as published by the Free Software Foundation; either |
paulb@274 | 12 | version 2.1 of the License, or (at your option) any later version. |
paulb@274 | 13 | |
paulb@274 | 14 | This library is distributed in the hope that it will be useful, |
paulb@274 | 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
paulb@274 | 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
paulb@274 | 17 | Lesser General Public License for more details. |
paulb@274 | 18 | |
paulb@274 | 19 | You should have received a copy of the GNU Lesser General Public |
paulb@274 | 20 | License along with this library; if not, write to the Free Software |
paulb@412 | 21 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
paulb@274 | 22 | --> |
paulb@233 | 23 | <xsl:stylesheet version="1.0" |
paulb@233 | 24 | xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
paulb@233 | 25 | xmlns:template="http://www.boddie.org.uk/ns/xmltools/template"> |
paulb@233 | 26 | |
paulb@233 | 27 | <xsl:output indent="yes"/> |
paulb@233 | 28 | |
paulb@258 | 29 | <!-- Input fields. --> |
paulb@426 | 30 | <!-- Format: attribute --> |
paulb@258 | 31 | |
paulb@233 | 32 | <xsl:template match="*[@template:attribute-field]"> |
paulb@233 | 33 | <xsl:copy> |
paulb@237 | 34 | <!-- Remove attribute-field and replace name and value. --> |
paulb@237 | 35 | <xsl:apply-templates select="@*[local-name() != 'attribute-field' and local-name() != 'name' and local-name() != 'value']"/> |
paulb@233 | 36 | <xsl:attribute name="template:attribute"><xsl:value-of select="@template:attribute-field"/></xsl:attribute> |
paulb@233 | 37 | <xsl:attribute name="name">{template:this-attribute()}</xsl:attribute> |
paulb@233 | 38 | <xsl:attribute name="value">{$this-value}</xsl:attribute> |
paulb@233 | 39 | <xsl:apply-templates select="*|node()"/> |
paulb@233 | 40 | </xsl:copy> |
paulb@233 | 41 | </xsl:template> |
paulb@233 | 42 | |
paulb@258 | 43 | <!-- Text areas and other elements without value attributes. --> |
paulb@426 | 44 | <!-- Format: attribute[,effect] --> |
paulb@258 | 45 | |
paulb@258 | 46 | <xsl:template match="*[@template:attribute-area]"> |
paulb@262 | 47 | <xsl:variable name="field-attr" select="substring-before(@template:attribute-area, ',')"/> |
paulb@262 | 48 | <xsl:variable name="field-effect" select="substring-after(@template:attribute-area, ',')"/> |
paulb@258 | 49 | <xsl:copy> |
paulb@262 | 50 | <!-- Remove attribute-area and replace name. --> |
paulb@262 | 51 | <xsl:apply-templates select="@*[local-name() != 'attribute-area' and local-name() != 'name']"/> |
paulb@262 | 52 | <xsl:choose> |
paulb@262 | 53 | <xsl:when test="$field-attr != ''"> |
paulb@262 | 54 | <xsl:attribute name="template:attribute"><xsl:value-of select="$field-attr"/></xsl:attribute> |
paulb@262 | 55 | <xsl:if test="$field-effect != ''"> |
paulb@262 | 56 | <xsl:attribute name="template:effect"><xsl:value-of select="$field-effect"/></xsl:attribute> |
paulb@262 | 57 | </xsl:if> |
paulb@401 | 58 | <xsl:attribute name="template:value">$this-value</xsl:attribute> |
paulb@262 | 59 | </xsl:when> |
paulb@262 | 60 | <xsl:otherwise> |
paulb@262 | 61 | <xsl:attribute name="template:attribute"><xsl:value-of select="@template:attribute-area"/></xsl:attribute> |
paulb@401 | 62 | <xsl:attribute name="template:value">$this-value</xsl:attribute> |
paulb@262 | 63 | </xsl:otherwise> |
paulb@262 | 64 | </xsl:choose> |
paulb@258 | 65 | <xsl:attribute name="name">{template:this-attribute()}</xsl:attribute> |
paulb@258 | 66 | <xsl:apply-templates select="*|node()"/> |
paulb@258 | 67 | </xsl:copy> |
paulb@258 | 68 | </xsl:template> |
paulb@258 | 69 | |
paulb@258 | 70 | <!-- Buttons whose state varies according to an attribute. --> |
paulb@426 | 71 | <!-- Format: attribute,value,attribute-to-set --> |
paulb@258 | 72 | |
paulb@254 | 73 | <xsl:template match="*[@template:attribute-button]"> |
paulb@254 | 74 | <xsl:variable name="field-attr" select="substring-before(@template:attribute-button, ',')"/> |
paulb@262 | 75 | <xsl:variable name="field-info" select="substring-after(@template:attribute-button, ',')"/> |
paulb@262 | 76 | <xsl:variable name="field-value" select="substring-before($field-info, ',')"/> |
paulb@262 | 77 | <xsl:variable name="field-set-attr" select="substring-after($field-info, ',')"/> |
paulb@254 | 78 | <xsl:copy> |
paulb@254 | 79 | <!-- Remove attribute-button and replace name. --> |
paulb@254 | 80 | <xsl:apply-templates select="@*[local-name() != 'attribute-button' and local-name() != 'name']"/> |
paulb@254 | 81 | <xsl:attribute name="template:attribute"><xsl:value-of select="$field-attr"/></xsl:attribute> |
paulb@254 | 82 | <xsl:attribute name="template:expr-attr"><xsl:value-of select="$field-set-attr"/></xsl:attribute> |
paulb@262 | 83 | <xsl:attribute name="template:expr">$this-value = '<xsl:value-of select="$field-value"/>'</xsl:attribute> |
paulb@254 | 84 | <xsl:attribute name="name">{template:this-attribute()}</xsl:attribute> |
paulb@262 | 85 | <xsl:attribute name="value"><xsl:value-of select="$field-value"/></xsl:attribute> |
paulb@254 | 86 | <xsl:apply-templates select="*|node()"/> |
paulb@254 | 87 | </xsl:copy> |
paulb@254 | 88 | </xsl:template> |
paulb@254 | 89 | |
paulb@280 | 90 | <!-- Buttons whose state varies according to an attribute in a list of multiple choice elements. --> |
paulb@426 | 91 | <!-- Format: attribute,attribute-to-set --> |
paulb@280 | 92 | |
paulb@280 | 93 | <xsl:template match="*[@template:attribute-list-button]"> |
paulb@280 | 94 | <xsl:variable name="field-attr" select="substring-before(@template:attribute-list-button, ',')"/> |
paulb@280 | 95 | <xsl:variable name="field-set-attr" select="substring-after(@template:attribute-list-button, ',')"/> |
paulb@280 | 96 | <xsl:copy> |
paulb@280 | 97 | <!-- Remove attribute-button and replace name. --> |
paulb@280 | 98 | <xsl:apply-templates select="@*[local-name() != 'attribute-button' and local-name() != 'name']"/> |
paulb@280 | 99 | <xsl:attribute name="template:attribute"><xsl:value-of select="$field-attr"/></xsl:attribute> |
paulb@280 | 100 | <xsl:attribute name="template:expr-attr"><xsl:value-of select="$field-set-attr"/></xsl:attribute> |
paulb@280 | 101 | <xsl:attribute name="template:expr">@value-is-set</xsl:attribute> |
paulb@280 | 102 | <xsl:attribute name="name">{template:this-attribute()}</xsl:attribute> |
paulb@280 | 103 | <xsl:attribute name="value">{$this-value}</xsl:attribute> |
paulb@280 | 104 | <xsl:apply-templates select="*|node()"/> |
paulb@280 | 105 | </xsl:copy> |
paulb@280 | 106 | </xsl:template> |
paulb@280 | 107 | |
paulb@258 | 108 | <!-- Selectors. --> |
paulb@426 | 109 | <!-- Format: name[,affected-element] --> |
paulb@258 | 110 | |
paulb@233 | 111 | <xsl:template match="*[@template:selector-field]"> |
paulb@258 | 112 | <xsl:variable name="field-name" select="substring-before(@template:selector-field, ',')"/> |
paulb@258 | 113 | <xsl:variable name="affected-element" select="substring-after(@template:selector-field, ',')"/> |
paulb@233 | 114 | <xsl:copy> |
paulb@237 | 115 | <!-- Remove selector-field and replace name. --> |
paulb@237 | 116 | <xsl:apply-templates select="@*[local-name() != 'selector-field' and local-name() != 'name']"/> |
paulb@258 | 117 | <xsl:choose> |
paulb@258 | 118 | <xsl:when test="$field-name != ''"> |
paulb@258 | 119 | <xsl:attribute name="name"><xsl:value-of select="$field-name"/>={template:this-element()}</xsl:attribute> |
paulb@258 | 120 | </xsl:when> |
paulb@258 | 121 | <xsl:otherwise> |
paulb@258 | 122 | <xsl:attribute name="name"><xsl:value-of select="@template:selector-field"/>={template:this-element()}</xsl:attribute> |
paulb@258 | 123 | </xsl:otherwise> |
paulb@258 | 124 | </xsl:choose> |
paulb@233 | 125 | <xsl:apply-templates select="*|node()"/> |
paulb@233 | 126 | </xsl:copy> |
paulb@233 | 127 | </xsl:template> |
paulb@233 | 128 | |
paulb@258 | 129 | <!-- Multiple choice fields, represented by menus and listboxes. --> |
paulb@426 | 130 | <!-- Format: element,attribute[,attribute-type] --> |
paulb@258 | 131 | |
paulb@233 | 132 | <xsl:template match="*[@template:multiple-choice-field]"> |
paulb@233 | 133 | <xsl:variable name="field-element" select="substring-before(@template:multiple-choice-field, ',')"/> |
paulb@263 | 134 | <xsl:variable name="field-attr-info" select="substring-after(@template:multiple-choice-field, ',')"/> |
paulb@263 | 135 | <xsl:variable name="field-attr" select="substring-before($field-attr-info, ',')"/> |
paulb@263 | 136 | <xsl:variable name="field-attr-type" select="substring-after($field-attr-info, ',')"/> |
paulb@233 | 137 | <xsl:copy> |
paulb@237 | 138 | <!-- Remove multiple-choice-field and replace name. --> |
paulb@237 | 139 | <xsl:apply-templates select="@*[local-name() != 'multiple-choice-field' and local-name() != 'name']"/> |
paulb@262 | 140 | <xsl:if test="$field-element != '-'"> |
paulb@262 | 141 | <xsl:attribute name="template:element"><xsl:value-of select="$field-element"/></xsl:attribute> |
paulb@262 | 142 | </xsl:if> |
paulb@263 | 143 | <xsl:choose> |
paulb@263 | 144 | <xsl:when test="$field-attr-type = 'new'"> |
paulb@263 | 145 | <xsl:attribute name="name">{template:new-attribute('<xsl:value-of select="$field-attr"/>')}</xsl:attribute> |
paulb@263 | 146 | </xsl:when> |
paulb@263 | 147 | <xsl:when test="$field-attr = ''"> |
paulb@263 | 148 | <xsl:attribute name="template:attribute"><xsl:value-of select="$field-attr-info"/></xsl:attribute> |
paulb@263 | 149 | <xsl:attribute name="name">{template:this-attribute()}</xsl:attribute> |
paulb@263 | 150 | </xsl:when> |
paulb@263 | 151 | <xsl:otherwise> |
paulb@263 | 152 | <xsl:attribute name="template:attribute"><xsl:value-of select="$field-attr"/></xsl:attribute> |
paulb@263 | 153 | <xsl:attribute name="name">{template:this-attribute()}</xsl:attribute> |
paulb@263 | 154 | </xsl:otherwise> |
paulb@263 | 155 | </xsl:choose> |
paulb@233 | 156 | <xsl:apply-templates select="*|node()"/> |
paulb@233 | 157 | </xsl:copy> |
paulb@233 | 158 | </xsl:template> |
paulb@233 | 159 | |
paulb@258 | 160 | <!-- Multiple choice list fields, represented by menus and listboxes with multiple values. --> |
paulb@426 | 161 | <!-- Format: element,list-element,list-attribute --> |
paulb@258 | 162 | |
paulb@258 | 163 | <xsl:template match="*[@template:multiple-choice-list-field]"> |
paulb@258 | 164 | <xsl:variable name="field-element" select="substring-before(@template:multiple-choice-list-field, ',')"/> |
paulb@258 | 165 | <xsl:variable name="field-list-info" select="substring-after(@template:multiple-choice-list-field, ',')"/> |
paulb@258 | 166 | <xsl:variable name="field-list-element" select="substring-before($field-list-info, ',')"/> |
paulb@258 | 167 | <xsl:variable name="field-list-attr" select="substring-after($field-list-info, ',')"/> |
paulb@258 | 168 | <xsl:copy> |
paulb@258 | 169 | <!-- Remove multiple-choice-list-field and replace name. --> |
paulb@258 | 170 | <xsl:apply-templates select="@*[local-name() != 'multiple-choice-list-field' and local-name() != 'name']"/> |
paulb@262 | 171 | <xsl:if test="$field-element != '-'"> |
paulb@262 | 172 | <xsl:attribute name="template:element"><xsl:value-of select="$field-element"/></xsl:attribute> |
paulb@262 | 173 | </xsl:if> |
paulb@258 | 174 | <xsl:attribute name="name">{template:list-attribute('<xsl:value-of select="$field-list-element"/>', |
paulb@258 | 175 | '<xsl:value-of select="$field-list-attr"/>')}</xsl:attribute> |
paulb@258 | 176 | <xsl:apply-templates select="*|node()"/> |
paulb@258 | 177 | </xsl:copy> |
paulb@258 | 178 | </xsl:template> |
paulb@258 | 179 | |
paulb@258 | 180 | <!-- Multiple choice values, represented by option elements. --> |
paulb@426 | 181 | <!-- Format: element,attribute,attribute-to-set[,contents-expr] --> |
paulb@258 | 182 | |
paulb@233 | 183 | <xsl:template match="*[@template:multiple-choice-value]"> |
paulb@233 | 184 | <xsl:variable name="field-element" select="substring-before(@template:multiple-choice-value, ',')"/> |
paulb@233 | 185 | <xsl:variable name="field-attr-info" select="substring-after(@template:multiple-choice-value, ',')"/> |
paulb@233 | 186 | <xsl:variable name="field-attr" select="substring-before($field-attr-info, ',')"/> |
paulb@426 | 187 | <xsl:variable name="field-set-attr-info" select="substring-after($field-attr-info, ',')"/> |
paulb@426 | 188 | <xsl:variable name="field-set-attr" select="substring-before($field-set-attr-info, ',')"/> |
paulb@426 | 189 | <xsl:variable name="field-contents" select="substring-after($field-set-attr-info, ',')"/> |
paulb@233 | 190 | <xsl:copy> |
paulb@237 | 191 | <!-- Remove multiple-choice-value and replace value. --> |
paulb@237 | 192 | <xsl:apply-templates select="@*[local-name() != 'multiple-choice-value' and local-name() != 'value']"/> |
paulb@233 | 193 | <xsl:attribute name="template:element"><xsl:value-of select="$field-element"/></xsl:attribute> |
paulb@233 | 194 | <xsl:attribute name="template:expr">@<xsl:value-of select="$field-attr"/> = ../@<xsl:value-of select="$field-attr"/></xsl:attribute> |
paulb@426 | 195 | <!-- For the option text... --> |
paulb@426 | 196 | <xsl:choose> |
paulb@426 | 197 | <!-- Either provide the stated attribute as the eventual text of an option element. --> |
paulb@426 | 198 | <xsl:when test="$field-set-attr = ''"> |
paulb@426 | 199 | <xsl:attribute name="template:expr-attr"><xsl:value-of select="$field-set-attr-info"/></xsl:attribute> |
paulb@426 | 200 | <xsl:attribute name="template:value">@<xsl:value-of select="$field-attr"/></xsl:attribute> |
paulb@426 | 201 | </xsl:when> |
paulb@426 | 202 | <!-- Or get the specific contents. --> |
paulb@426 | 203 | <xsl:otherwise> |
paulb@426 | 204 | <xsl:attribute name="template:expr-attr"><xsl:value-of select="$field-set-attr"/></xsl:attribute> |
paulb@426 | 205 | <xsl:attribute name="template:value"><xsl:value-of select="$field-contents"/></xsl:attribute> |
paulb@426 | 206 | </xsl:otherwise> |
paulb@426 | 207 | </xsl:choose> |
paulb@233 | 208 | <xsl:attribute name="value">{@<xsl:value-of select="$field-attr"/>}</xsl:attribute> |
paulb@233 | 209 | <xsl:apply-templates select="*|node()"/> |
paulb@233 | 210 | </xsl:copy> |
paulb@233 | 211 | </xsl:template> |
paulb@233 | 212 | |
paulb@258 | 213 | <!-- Multiple choice list values, represented by option elements. --> |
paulb@426 | 214 | <!-- Format: list-element,list-attribute,attribute-to-set[,contents-expr] --> |
paulb@258 | 215 | |
paulb@258 | 216 | <xsl:template match="*[@template:multiple-choice-list-value]"> |
paulb@258 | 217 | <xsl:variable name="field-element" select="substring-before(@template:multiple-choice-list-value, ',')"/> |
paulb@258 | 218 | <xsl:variable name="field-attr-info" select="substring-after(@template:multiple-choice-list-value, ',')"/> |
paulb@258 | 219 | <xsl:variable name="field-attr" select="substring-before($field-attr-info, ',')"/> |
paulb@426 | 220 | <xsl:variable name="field-set-attr-info" select="substring-after($field-attr-info, ',')"/> |
paulb@426 | 221 | <xsl:variable name="field-set-attr" select="substring-before($field-set-attr-info, ',')"/> |
paulb@426 | 222 | <xsl:variable name="field-contents" select="substring-after($field-set-attr-info, ',')"/> |
paulb@258 | 223 | <xsl:copy> |
paulb@258 | 224 | <!-- Remove multiple-choice-value and replace value. --> |
paulb@258 | 225 | <xsl:apply-templates select="@*[local-name() != 'multiple-choice-list-value' and local-name() != 'value']"/> |
paulb@258 | 226 | <xsl:attribute name="template:element"><xsl:value-of select="$field-element"/></xsl:attribute> |
paulb@258 | 227 | <xsl:attribute name="template:expr">@value-is-set</xsl:attribute> |
paulb@426 | 228 | <!-- For the option text... --> |
paulb@426 | 229 | <xsl:choose> |
paulb@426 | 230 | <!-- Either provide the stated attribute as the eventual text of an option element. --> |
paulb@426 | 231 | <xsl:when test="$field-set-attr = ''"> |
paulb@426 | 232 | <xsl:attribute name="template:expr-attr"><xsl:value-of select="$field-set-attr-info"/></xsl:attribute> |
paulb@426 | 233 | <xsl:attribute name="template:value">@<xsl:value-of select="$field-attr"/></xsl:attribute> |
paulb@426 | 234 | </xsl:when> |
paulb@426 | 235 | <!-- Or get the specific contents. --> |
paulb@426 | 236 | <xsl:otherwise> |
paulb@426 | 237 | <xsl:attribute name="template:expr-attr"><xsl:value-of select="$field-set-attr"/></xsl:attribute> |
paulb@426 | 238 | <xsl:attribute name="template:value"><xsl:value-of select="$field-contents"/></xsl:attribute> |
paulb@426 | 239 | </xsl:otherwise> |
paulb@426 | 240 | </xsl:choose> |
paulb@258 | 241 | <xsl:attribute name="value">{@<xsl:value-of select="$field-attr"/>}</xsl:attribute> |
paulb@258 | 242 | <xsl:apply-templates select="*|node()"/> |
paulb@258 | 243 | </xsl:copy> |
paulb@258 | 244 | </xsl:template> |
paulb@258 | 245 | |
paulb@280 | 246 | <!-- Multiple choice elements. --> |
paulb@426 | 247 | <!-- Format: element,list-element,list-attribute --> |
paulb@280 | 248 | |
paulb@280 | 249 | <xsl:template match="*[@template:multiple-choice-list-element]"> |
paulb@280 | 250 | <xsl:variable name="element" select="substring-before(@template:multiple-choice-list-element, ',')"/> |
paulb@280 | 251 | <xsl:variable name="element-list-info" select="substring-after(@template:multiple-choice-list-element, ',')"/> |
paulb@280 | 252 | <xsl:variable name="element-list-element" select="substring-before($element-list-info, ',')"/> |
paulb@280 | 253 | <xsl:variable name="element-list-attr" select="substring-after($element-list-info, ',')"/> |
paulb@280 | 254 | <xsl:copy> |
paulb@280 | 255 | <!-- Remove multiple-choice-list-element. --> |
paulb@280 | 256 | <xsl:apply-templates select="@*[local-name() != 'multiple-choice-list-value']"/> |
paulb@280 | 257 | <xsl:attribute name="template:element"><xsl:value-of select="$element"/>,<xsl:value-of select="$element-list-element"/></xsl:attribute> |
paulb@280 | 258 | <!-- The attribute is ignored - it is only useful in the schema and input processes. --> |
paulb@280 | 259 | <xsl:apply-templates select="*|node()"/> |
paulb@280 | 260 | </xsl:copy> |
paulb@280 | 261 | </xsl:template> |
paulb@280 | 262 | |
paulb@233 | 263 | <!-- Replicate unknown elements. --> |
paulb@233 | 264 | |
paulb@233 | 265 | <xsl:template match="@*|node()"> |
paulb@233 | 266 | <xsl:copy> |
paulb@233 | 267 | <xsl:apply-templates select="@*|node()"/> |
paulb@233 | 268 | </xsl:copy> |
paulb@233 | 269 | </xsl:template> |
paulb@233 | 270 | |
paulb@233 | 271 | </xsl:stylesheet> |