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@258 | 25 | <!-- Input fields. --> |
paulb@258 | 26 | |
paulb@233 | 27 | <xsl:template match="*[@template:attribute-field]"> |
paulb@233 | 28 | <xsl:copy> |
paulb@237 | 29 | <!-- Remove attribute-field and replace name and value. --> |
paulb@237 | 30 | <xsl:apply-templates select="@*[local-name() != 'attribute-field' and local-name() != 'name' and local-name() != 'value']"/> |
paulb@233 | 31 | <xsl:attribute name="template:attribute"><xsl:value-of select="@template:attribute-field"/></xsl:attribute> |
paulb@233 | 32 | <xsl:attribute name="name">{template:this-attribute()}</xsl:attribute> |
paulb@233 | 33 | <xsl:attribute name="value">{$this-value}</xsl:attribute> |
paulb@233 | 34 | <xsl:apply-templates select="*|node()"/> |
paulb@233 | 35 | </xsl:copy> |
paulb@233 | 36 | </xsl:template> |
paulb@233 | 37 | |
paulb@258 | 38 | <!-- Text areas and other elements without value attributes. --> |
paulb@258 | 39 | |
paulb@258 | 40 | <xsl:template match="*[@template:attribute-area]"> |
paulb@262 | 41 | <xsl:variable name="field-attr" select="substring-before(@template:attribute-area, ',')"/> |
paulb@262 | 42 | <xsl:variable name="field-effect" select="substring-after(@template:attribute-area, ',')"/> |
paulb@258 | 43 | <xsl:copy> |
paulb@262 | 44 | <!-- Remove attribute-area and replace name. --> |
paulb@262 | 45 | <xsl:apply-templates select="@*[local-name() != 'attribute-area' and local-name() != 'name']"/> |
paulb@262 | 46 | <xsl:choose> |
paulb@262 | 47 | <xsl:when test="$field-attr != ''"> |
paulb@262 | 48 | <xsl:attribute name="template:attribute"><xsl:value-of select="$field-attr"/></xsl:attribute> |
paulb@262 | 49 | <xsl:if test="$field-effect != ''"> |
paulb@262 | 50 | <xsl:attribute name="template:effect"><xsl:value-of select="$field-effect"/></xsl:attribute> |
paulb@262 | 51 | </xsl:if> |
paulb@401 | 52 | <xsl:attribute name="template:value">$this-value</xsl:attribute> |
paulb@262 | 53 | </xsl:when> |
paulb@262 | 54 | <xsl:otherwise> |
paulb@262 | 55 | <xsl:attribute name="template:attribute"><xsl:value-of select="@template:attribute-area"/></xsl:attribute> |
paulb@401 | 56 | <xsl:attribute name="template:value">$this-value</xsl:attribute> |
paulb@262 | 57 | </xsl:otherwise> |
paulb@262 | 58 | </xsl:choose> |
paulb@258 | 59 | <xsl:attribute name="name">{template:this-attribute()}</xsl:attribute> |
paulb@258 | 60 | <xsl:apply-templates select="*|node()"/> |
paulb@258 | 61 | </xsl:copy> |
paulb@258 | 62 | </xsl:template> |
paulb@258 | 63 | |
paulb@258 | 64 | <!-- Buttons whose state varies according to an attribute. --> |
paulb@258 | 65 | |
paulb@254 | 66 | <xsl:template match="*[@template:attribute-button]"> |
paulb@254 | 67 | <xsl:variable name="field-attr" select="substring-before(@template:attribute-button, ',')"/> |
paulb@262 | 68 | <xsl:variable name="field-info" select="substring-after(@template:attribute-button, ',')"/> |
paulb@262 | 69 | <xsl:variable name="field-value" select="substring-before($field-info, ',')"/> |
paulb@262 | 70 | <xsl:variable name="field-set-attr" select="substring-after($field-info, ',')"/> |
paulb@254 | 71 | <xsl:copy> |
paulb@254 | 72 | <!-- Remove attribute-button and replace name. --> |
paulb@254 | 73 | <xsl:apply-templates select="@*[local-name() != 'attribute-button' and local-name() != 'name']"/> |
paulb@254 | 74 | <xsl:attribute name="template:attribute"><xsl:value-of select="$field-attr"/></xsl:attribute> |
paulb@254 | 75 | <xsl:attribute name="template:expr-attr"><xsl:value-of select="$field-set-attr"/></xsl:attribute> |
paulb@262 | 76 | <xsl:attribute name="template:expr">$this-value = '<xsl:value-of select="$field-value"/>'</xsl:attribute> |
paulb@254 | 77 | <xsl:attribute name="name">{template:this-attribute()}</xsl:attribute> |
paulb@262 | 78 | <xsl:attribute name="value"><xsl:value-of select="$field-value"/></xsl:attribute> |
paulb@254 | 79 | <xsl:apply-templates select="*|node()"/> |
paulb@254 | 80 | </xsl:copy> |
paulb@254 | 81 | </xsl:template> |
paulb@254 | 82 | |
paulb@280 | 83 | <!-- Buttons whose state varies according to an attribute in a list of multiple choice elements. --> |
paulb@280 | 84 | |
paulb@280 | 85 | <xsl:template match="*[@template:attribute-list-button]"> |
paulb@280 | 86 | <xsl:variable name="field-attr" select="substring-before(@template:attribute-list-button, ',')"/> |
paulb@280 | 87 | <xsl:variable name="field-set-attr" select="substring-after(@template:attribute-list-button, ',')"/> |
paulb@280 | 88 | <xsl:copy> |
paulb@280 | 89 | <!-- Remove attribute-button and replace name. --> |
paulb@280 | 90 | <xsl:apply-templates select="@*[local-name() != 'attribute-button' and local-name() != 'name']"/> |
paulb@280 | 91 | <xsl:attribute name="template:attribute"><xsl:value-of select="$field-attr"/></xsl:attribute> |
paulb@280 | 92 | <xsl:attribute name="template:expr-attr"><xsl:value-of select="$field-set-attr"/></xsl:attribute> |
paulb@280 | 93 | <xsl:attribute name="template:expr">@value-is-set</xsl:attribute> |
paulb@280 | 94 | <xsl:attribute name="name">{template:this-attribute()}</xsl:attribute> |
paulb@280 | 95 | <xsl:attribute name="value">{$this-value}</xsl:attribute> |
paulb@280 | 96 | <xsl:apply-templates select="*|node()"/> |
paulb@280 | 97 | </xsl:copy> |
paulb@280 | 98 | </xsl:template> |
paulb@280 | 99 | |
paulb@258 | 100 | <!-- Selectors. --> |
paulb@258 | 101 | |
paulb@233 | 102 | <xsl:template match="*[@template:selector-field]"> |
paulb@258 | 103 | <xsl:variable name="field-name" select="substring-before(@template:selector-field, ',')"/> |
paulb@258 | 104 | <xsl:variable name="affected-element" select="substring-after(@template:selector-field, ',')"/> |
paulb@233 | 105 | <xsl:copy> |
paulb@237 | 106 | <!-- Remove selector-field and replace name. --> |
paulb@237 | 107 | <xsl:apply-templates select="@*[local-name() != 'selector-field' and local-name() != 'name']"/> |
paulb@258 | 108 | <xsl:choose> |
paulb@258 | 109 | <xsl:when test="$field-name != ''"> |
paulb@258 | 110 | <xsl:attribute name="name"><xsl:value-of select="$field-name"/>={template:this-element()}</xsl:attribute> |
paulb@258 | 111 | </xsl:when> |
paulb@258 | 112 | <xsl:otherwise> |
paulb@258 | 113 | <xsl:attribute name="name"><xsl:value-of select="@template:selector-field"/>={template:this-element()}</xsl:attribute> |
paulb@258 | 114 | </xsl:otherwise> |
paulb@258 | 115 | </xsl:choose> |
paulb@233 | 116 | <xsl:apply-templates select="*|node()"/> |
paulb@233 | 117 | </xsl:copy> |
paulb@233 | 118 | </xsl:template> |
paulb@233 | 119 | |
paulb@258 | 120 | <!-- Multiple choice fields, represented by menus and listboxes. --> |
paulb@258 | 121 | |
paulb@233 | 122 | <xsl:template match="*[@template:multiple-choice-field]"> |
paulb@233 | 123 | <xsl:variable name="field-element" select="substring-before(@template:multiple-choice-field, ',')"/> |
paulb@263 | 124 | <xsl:variable name="field-attr-info" select="substring-after(@template:multiple-choice-field, ',')"/> |
paulb@263 | 125 | <xsl:variable name="field-attr" select="substring-before($field-attr-info, ',')"/> |
paulb@263 | 126 | <xsl:variable name="field-attr-type" select="substring-after($field-attr-info, ',')"/> |
paulb@233 | 127 | <xsl:copy> |
paulb@237 | 128 | <!-- Remove multiple-choice-field and replace name. --> |
paulb@237 | 129 | <xsl:apply-templates select="@*[local-name() != 'multiple-choice-field' and local-name() != 'name']"/> |
paulb@262 | 130 | <xsl:if test="$field-element != '-'"> |
paulb@262 | 131 | <xsl:attribute name="template:element"><xsl:value-of select="$field-element"/></xsl:attribute> |
paulb@262 | 132 | </xsl:if> |
paulb@263 | 133 | <xsl:choose> |
paulb@263 | 134 | <xsl:when test="$field-attr-type = 'new'"> |
paulb@263 | 135 | <xsl:attribute name="name">{template:new-attribute('<xsl:value-of select="$field-attr"/>')}</xsl:attribute> |
paulb@263 | 136 | </xsl:when> |
paulb@263 | 137 | <xsl:when test="$field-attr = ''"> |
paulb@263 | 138 | <xsl:attribute name="template:attribute"><xsl:value-of select="$field-attr-info"/></xsl:attribute> |
paulb@263 | 139 | <xsl:attribute name="name">{template:this-attribute()}</xsl:attribute> |
paulb@263 | 140 | </xsl:when> |
paulb@263 | 141 | <xsl:otherwise> |
paulb@263 | 142 | <xsl:attribute name="template:attribute"><xsl:value-of select="$field-attr"/></xsl:attribute> |
paulb@263 | 143 | <xsl:attribute name="name">{template:this-attribute()}</xsl:attribute> |
paulb@263 | 144 | </xsl:otherwise> |
paulb@263 | 145 | </xsl:choose> |
paulb@233 | 146 | <xsl:apply-templates select="*|node()"/> |
paulb@233 | 147 | </xsl:copy> |
paulb@233 | 148 | </xsl:template> |
paulb@233 | 149 | |
paulb@258 | 150 | <!-- Multiple choice list fields, represented by menus and listboxes with multiple values. --> |
paulb@258 | 151 | |
paulb@258 | 152 | <xsl:template match="*[@template:multiple-choice-list-field]"> |
paulb@258 | 153 | <xsl:variable name="field-element" select="substring-before(@template:multiple-choice-list-field, ',')"/> |
paulb@258 | 154 | <xsl:variable name="field-list-info" select="substring-after(@template:multiple-choice-list-field, ',')"/> |
paulb@258 | 155 | <xsl:variable name="field-list-element" select="substring-before($field-list-info, ',')"/> |
paulb@258 | 156 | <xsl:variable name="field-list-attr" select="substring-after($field-list-info, ',')"/> |
paulb@258 | 157 | <xsl:copy> |
paulb@258 | 158 | <!-- Remove multiple-choice-list-field and replace name. --> |
paulb@258 | 159 | <xsl:apply-templates select="@*[local-name() != 'multiple-choice-list-field' and local-name() != 'name']"/> |
paulb@262 | 160 | <xsl:if test="$field-element != '-'"> |
paulb@262 | 161 | <xsl:attribute name="template:element"><xsl:value-of select="$field-element"/></xsl:attribute> |
paulb@262 | 162 | </xsl:if> |
paulb@258 | 163 | <xsl:attribute name="name">{template:list-attribute('<xsl:value-of select="$field-list-element"/>', |
paulb@258 | 164 | '<xsl:value-of select="$field-list-attr"/>')}</xsl:attribute> |
paulb@258 | 165 | <xsl:apply-templates select="*|node()"/> |
paulb@258 | 166 | </xsl:copy> |
paulb@258 | 167 | </xsl:template> |
paulb@258 | 168 | |
paulb@258 | 169 | <!-- Multiple choice values, represented by option elements. --> |
paulb@258 | 170 | |
paulb@233 | 171 | <xsl:template match="*[@template:multiple-choice-value]"> |
paulb@233 | 172 | <xsl:variable name="field-element" select="substring-before(@template:multiple-choice-value, ',')"/> |
paulb@233 | 173 | <xsl:variable name="field-attr-info" select="substring-after(@template:multiple-choice-value, ',')"/> |
paulb@233 | 174 | <xsl:variable name="field-attr" select="substring-before($field-attr-info, ',')"/> |
paulb@233 | 175 | <xsl:variable name="field-set-attr" select="substring-after($field-attr-info, ',')"/> |
paulb@233 | 176 | <xsl:copy> |
paulb@237 | 177 | <!-- Remove multiple-choice-value and replace value. --> |
paulb@237 | 178 | <xsl:apply-templates select="@*[local-name() != 'multiple-choice-value' and local-name() != 'value']"/> |
paulb@233 | 179 | <xsl:attribute name="template:element"><xsl:value-of select="$field-element"/></xsl:attribute> |
paulb@233 | 180 | <xsl:attribute name="template:expr">@<xsl:value-of select="$field-attr"/> = ../@<xsl:value-of select="$field-attr"/></xsl:attribute> |
paulb@233 | 181 | <xsl:attribute name="template:expr-attr"><xsl:value-of select="$field-set-attr"/></xsl:attribute> |
paulb@233 | 182 | <xsl:attribute name="template:value">@<xsl:value-of select="$field-attr"/></xsl:attribute> |
paulb@233 | 183 | <xsl:attribute name="value">{@<xsl:value-of select="$field-attr"/>}</xsl:attribute> |
paulb@233 | 184 | <xsl:apply-templates select="*|node()"/> |
paulb@233 | 185 | </xsl:copy> |
paulb@233 | 186 | </xsl:template> |
paulb@233 | 187 | |
paulb@258 | 188 | <!-- Multiple choice list values, represented by option elements. --> |
paulb@258 | 189 | |
paulb@258 | 190 | <xsl:template match="*[@template:multiple-choice-list-value]"> |
paulb@258 | 191 | <xsl:variable name="field-element" select="substring-before(@template:multiple-choice-list-value, ',')"/> |
paulb@258 | 192 | <xsl:variable name="field-attr-info" select="substring-after(@template:multiple-choice-list-value, ',')"/> |
paulb@258 | 193 | <xsl:variable name="field-attr" select="substring-before($field-attr-info, ',')"/> |
paulb@258 | 194 | <xsl:variable name="field-set-attr" select="substring-after($field-attr-info, ',')"/> |
paulb@258 | 195 | <xsl:copy> |
paulb@258 | 196 | <!-- Remove multiple-choice-value and replace value. --> |
paulb@258 | 197 | <xsl:apply-templates select="@*[local-name() != 'multiple-choice-list-value' and local-name() != 'value']"/> |
paulb@258 | 198 | <xsl:attribute name="template:element"><xsl:value-of select="$field-element"/></xsl:attribute> |
paulb@258 | 199 | <xsl:attribute name="template:expr">@value-is-set</xsl:attribute> |
paulb@258 | 200 | <xsl:attribute name="template:expr-attr"><xsl:value-of select="$field-set-attr"/></xsl:attribute> |
paulb@258 | 201 | <xsl:attribute name="template:value">@<xsl:value-of select="$field-attr"/></xsl:attribute> |
paulb@258 | 202 | <xsl:attribute name="value">{@<xsl:value-of select="$field-attr"/>}</xsl:attribute> |
paulb@258 | 203 | <xsl:apply-templates select="*|node()"/> |
paulb@258 | 204 | </xsl:copy> |
paulb@258 | 205 | </xsl:template> |
paulb@258 | 206 | |
paulb@280 | 207 | <!-- Multiple choice elements. --> |
paulb@280 | 208 | |
paulb@280 | 209 | <xsl:template match="*[@template:multiple-choice-list-element]"> |
paulb@280 | 210 | <xsl:variable name="element" select="substring-before(@template:multiple-choice-list-element, ',')"/> |
paulb@280 | 211 | <xsl:variable name="element-list-info" select="substring-after(@template:multiple-choice-list-element, ',')"/> |
paulb@280 | 212 | <xsl:variable name="element-list-element" select="substring-before($element-list-info, ',')"/> |
paulb@280 | 213 | <xsl:variable name="element-list-attr" select="substring-after($element-list-info, ',')"/> |
paulb@280 | 214 | <xsl:copy> |
paulb@280 | 215 | <!-- Remove multiple-choice-list-element. --> |
paulb@280 | 216 | <xsl:apply-templates select="@*[local-name() != 'multiple-choice-list-value']"/> |
paulb@280 | 217 | <xsl:attribute name="template:element"><xsl:value-of select="$element"/>,<xsl:value-of select="$element-list-element"/></xsl:attribute> |
paulb@280 | 218 | <!-- The attribute is ignored - it is only useful in the schema and input processes. --> |
paulb@280 | 219 | <xsl:apply-templates select="*|node()"/> |
paulb@280 | 220 | </xsl:copy> |
paulb@280 | 221 | </xsl:template> |
paulb@280 | 222 | |
paulb@233 | 223 | <!-- Replicate unknown elements. --> |
paulb@233 | 224 | |
paulb@233 | 225 | <xsl:template match="@*|node()"> |
paulb@233 | 226 | <xsl:copy> |
paulb@233 | 227 | <xsl:apply-templates select="@*|node()"/> |
paulb@233 | 228 | </xsl:copy> |
paulb@233 | 229 | </xsl:template> |
paulb@233 | 230 | |
paulb@233 | 231 | </xsl:stylesheet> |