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@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:attribute name="template:value">$this-value</xsl:attribute> |
paulb@262 | 52 | </xsl:if> |
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@262 | 56 | </xsl:otherwise> |
paulb@262 | 57 | </xsl:choose> |
paulb@258 | 58 | <xsl:attribute name="name">{template:this-attribute()}</xsl:attribute> |
paulb@258 | 59 | <xsl:apply-templates select="*|node()"/> |
paulb@258 | 60 | </xsl:copy> |
paulb@258 | 61 | </xsl:template> |
paulb@258 | 62 | |
paulb@258 | 63 | <!-- Buttons whose state varies according to an attribute. --> |
paulb@258 | 64 | |
paulb@254 | 65 | <xsl:template match="*[@template:attribute-button]"> |
paulb@254 | 66 | <xsl:variable name="field-attr" select="substring-before(@template:attribute-button, ',')"/> |
paulb@262 | 67 | <xsl:variable name="field-info" select="substring-after(@template:attribute-button, ',')"/> |
paulb@262 | 68 | <xsl:variable name="field-value" select="substring-before($field-info, ',')"/> |
paulb@262 | 69 | <xsl:variable name="field-set-attr" select="substring-after($field-info, ',')"/> |
paulb@254 | 70 | <xsl:copy> |
paulb@254 | 71 | <!-- Remove attribute-button and replace name. --> |
paulb@254 | 72 | <xsl:apply-templates select="@*[local-name() != 'attribute-button' and local-name() != 'name']"/> |
paulb@254 | 73 | <xsl:attribute name="template:attribute"><xsl:value-of select="$field-attr"/></xsl:attribute> |
paulb@254 | 74 | <xsl:attribute name="template:expr-attr"><xsl:value-of select="$field-set-attr"/></xsl:attribute> |
paulb@262 | 75 | <xsl:attribute name="template:expr">$this-value = '<xsl:value-of select="$field-value"/>'</xsl:attribute> |
paulb@254 | 76 | <xsl:attribute name="name">{template:this-attribute()}</xsl:attribute> |
paulb@262 | 77 | <xsl:attribute name="value"><xsl:value-of select="$field-value"/></xsl:attribute> |
paulb@254 | 78 | <xsl:apply-templates select="*|node()"/> |
paulb@254 | 79 | </xsl:copy> |
paulb@254 | 80 | </xsl:template> |
paulb@254 | 81 | |
paulb@258 | 82 | <!-- Selectors. --> |
paulb@258 | 83 | |
paulb@233 | 84 | <xsl:template match="*[@template:selector-field]"> |
paulb@258 | 85 | <xsl:variable name="field-name" select="substring-before(@template:selector-field, ',')"/> |
paulb@258 | 86 | <xsl:variable name="affected-element" select="substring-after(@template:selector-field, ',')"/> |
paulb@233 | 87 | <xsl:copy> |
paulb@237 | 88 | <!-- Remove selector-field and replace name. --> |
paulb@237 | 89 | <xsl:apply-templates select="@*[local-name() != 'selector-field' and local-name() != 'name']"/> |
paulb@258 | 90 | <xsl:choose> |
paulb@258 | 91 | <xsl:when test="$field-name != ''"> |
paulb@258 | 92 | <xsl:attribute name="name"><xsl:value-of select="$field-name"/>={template:this-element()}</xsl:attribute> |
paulb@258 | 93 | </xsl:when> |
paulb@258 | 94 | <xsl:otherwise> |
paulb@258 | 95 | <xsl:attribute name="name"><xsl:value-of select="@template:selector-field"/>={template:this-element()}</xsl:attribute> |
paulb@258 | 96 | </xsl:otherwise> |
paulb@258 | 97 | </xsl:choose> |
paulb@233 | 98 | <xsl:apply-templates select="*|node()"/> |
paulb@233 | 99 | </xsl:copy> |
paulb@233 | 100 | </xsl:template> |
paulb@233 | 101 | |
paulb@258 | 102 | <!-- Multiple choice fields, represented by menus and listboxes. --> |
paulb@258 | 103 | |
paulb@233 | 104 | <xsl:template match="*[@template:multiple-choice-field]"> |
paulb@233 | 105 | <xsl:variable name="field-element" select="substring-before(@template:multiple-choice-field, ',')"/> |
paulb@263 | 106 | <xsl:variable name="field-attr-info" select="substring-after(@template:multiple-choice-field, ',')"/> |
paulb@263 | 107 | <xsl:variable name="field-attr" select="substring-before($field-attr-info, ',')"/> |
paulb@263 | 108 | <xsl:variable name="field-attr-type" select="substring-after($field-attr-info, ',')"/> |
paulb@233 | 109 | <xsl:copy> |
paulb@237 | 110 | <!-- Remove multiple-choice-field and replace name. --> |
paulb@237 | 111 | <xsl:apply-templates select="@*[local-name() != 'multiple-choice-field' and local-name() != 'name']"/> |
paulb@262 | 112 | <xsl:if test="$field-element != '-'"> |
paulb@262 | 113 | <xsl:attribute name="template:element"><xsl:value-of select="$field-element"/></xsl:attribute> |
paulb@262 | 114 | </xsl:if> |
paulb@263 | 115 | <xsl:choose> |
paulb@263 | 116 | <xsl:when test="$field-attr-type = 'new'"> |
paulb@263 | 117 | <xsl:attribute name="name">{template:new-attribute('<xsl:value-of select="$field-attr"/>')}</xsl:attribute> |
paulb@263 | 118 | </xsl:when> |
paulb@263 | 119 | <xsl:when test="$field-attr = ''"> |
paulb@263 | 120 | <xsl:attribute name="template:attribute"><xsl:value-of select="$field-attr-info"/></xsl:attribute> |
paulb@263 | 121 | <xsl:attribute name="name">{template:this-attribute()}</xsl:attribute> |
paulb@263 | 122 | </xsl:when> |
paulb@263 | 123 | <xsl:otherwise> |
paulb@263 | 124 | <xsl:attribute name="template:attribute"><xsl:value-of select="$field-attr"/></xsl:attribute> |
paulb@263 | 125 | <xsl:attribute name="name">{template:this-attribute()}</xsl:attribute> |
paulb@263 | 126 | </xsl:otherwise> |
paulb@263 | 127 | </xsl:choose> |
paulb@233 | 128 | <xsl:apply-templates select="*|node()"/> |
paulb@233 | 129 | </xsl:copy> |
paulb@233 | 130 | </xsl:template> |
paulb@233 | 131 | |
paulb@258 | 132 | <!-- Multiple choice list fields, represented by menus and listboxes with multiple values. --> |
paulb@258 | 133 | |
paulb@258 | 134 | <xsl:template match="*[@template:multiple-choice-list-field]"> |
paulb@258 | 135 | <xsl:variable name="field-element" select="substring-before(@template:multiple-choice-list-field, ',')"/> |
paulb@258 | 136 | <xsl:variable name="field-list-info" select="substring-after(@template:multiple-choice-list-field, ',')"/> |
paulb@258 | 137 | <xsl:variable name="field-list-element" select="substring-before($field-list-info, ',')"/> |
paulb@258 | 138 | <xsl:variable name="field-list-attr" select="substring-after($field-list-info, ',')"/> |
paulb@258 | 139 | <xsl:copy> |
paulb@258 | 140 | <!-- Remove multiple-choice-list-field and replace name. --> |
paulb@258 | 141 | <xsl:apply-templates select="@*[local-name() != 'multiple-choice-list-field' and local-name() != 'name']"/> |
paulb@262 | 142 | <xsl:if test="$field-element != '-'"> |
paulb@262 | 143 | <xsl:attribute name="template:element"><xsl:value-of select="$field-element"/></xsl:attribute> |
paulb@262 | 144 | </xsl:if> |
paulb@258 | 145 | <xsl:attribute name="name">{template:list-attribute('<xsl:value-of select="$field-list-element"/>', |
paulb@258 | 146 | '<xsl:value-of select="$field-list-attr"/>')}</xsl:attribute> |
paulb@258 | 147 | <xsl:apply-templates select="*|node()"/> |
paulb@258 | 148 | </xsl:copy> |
paulb@258 | 149 | </xsl:template> |
paulb@258 | 150 | |
paulb@258 | 151 | <!-- Multiple choice values, represented by option elements. --> |
paulb@258 | 152 | |
paulb@233 | 153 | <xsl:template match="*[@template:multiple-choice-value]"> |
paulb@233 | 154 | <xsl:variable name="field-element" select="substring-before(@template:multiple-choice-value, ',')"/> |
paulb@233 | 155 | <xsl:variable name="field-attr-info" select="substring-after(@template:multiple-choice-value, ',')"/> |
paulb@233 | 156 | <xsl:variable name="field-attr" select="substring-before($field-attr-info, ',')"/> |
paulb@233 | 157 | <xsl:variable name="field-set-attr" select="substring-after($field-attr-info, ',')"/> |
paulb@233 | 158 | <xsl:copy> |
paulb@237 | 159 | <!-- Remove multiple-choice-value and replace value. --> |
paulb@237 | 160 | <xsl:apply-templates select="@*[local-name() != 'multiple-choice-value' and local-name() != 'value']"/> |
paulb@233 | 161 | <xsl:attribute name="template:element"><xsl:value-of select="$field-element"/></xsl:attribute> |
paulb@233 | 162 | <xsl:attribute name="template:expr">@<xsl:value-of select="$field-attr"/> = ../@<xsl:value-of select="$field-attr"/></xsl:attribute> |
paulb@233 | 163 | <xsl:attribute name="template:expr-attr"><xsl:value-of select="$field-set-attr"/></xsl:attribute> |
paulb@233 | 164 | <xsl:attribute name="template:value">@<xsl:value-of select="$field-attr"/></xsl:attribute> |
paulb@233 | 165 | <xsl:attribute name="value">{@<xsl:value-of select="$field-attr"/>}</xsl:attribute> |
paulb@233 | 166 | <xsl:apply-templates select="*|node()"/> |
paulb@233 | 167 | </xsl:copy> |
paulb@233 | 168 | </xsl:template> |
paulb@233 | 169 | |
paulb@258 | 170 | <!-- Multiple choice list values, represented by option elements. --> |
paulb@258 | 171 | |
paulb@258 | 172 | <xsl:template match="*[@template:multiple-choice-list-value]"> |
paulb@258 | 173 | <xsl:variable name="field-element" select="substring-before(@template:multiple-choice-list-value, ',')"/> |
paulb@258 | 174 | <xsl:variable name="field-attr-info" select="substring-after(@template:multiple-choice-list-value, ',')"/> |
paulb@258 | 175 | <xsl:variable name="field-attr" select="substring-before($field-attr-info, ',')"/> |
paulb@258 | 176 | <xsl:variable name="field-set-attr" select="substring-after($field-attr-info, ',')"/> |
paulb@258 | 177 | <xsl:copy> |
paulb@258 | 178 | <!-- Remove multiple-choice-value and replace value. --> |
paulb@258 | 179 | <xsl:apply-templates select="@*[local-name() != 'multiple-choice-list-value' and local-name() != 'value']"/> |
paulb@258 | 180 | <xsl:attribute name="template:element"><xsl:value-of select="$field-element"/></xsl:attribute> |
paulb@258 | 181 | <xsl:attribute name="template:expr">@value-is-set</xsl:attribute> |
paulb@258 | 182 | <xsl:attribute name="template:expr-attr"><xsl:value-of select="$field-set-attr"/></xsl:attribute> |
paulb@258 | 183 | <xsl:attribute name="template:value">@<xsl:value-of select="$field-attr"/></xsl:attribute> |
paulb@258 | 184 | <xsl:attribute name="value">{@<xsl:value-of select="$field-attr"/>}</xsl:attribute> |
paulb@258 | 185 | <xsl:apply-templates select="*|node()"/> |
paulb@258 | 186 | </xsl:copy> |
paulb@258 | 187 | </xsl:template> |
paulb@258 | 188 | |
paulb@233 | 189 | <!-- Replicate unknown elements. --> |
paulb@233 | 190 | |
paulb@233 | 191 | <xsl:template match="@*|node()"> |
paulb@233 | 192 | <xsl:copy> |
paulb@233 | 193 | <xsl:apply-templates select="@*|node()"/> |
paulb@233 | 194 | </xsl:copy> |
paulb@233 | 195 | </xsl:template> |
paulb@233 | 196 | |
paulb@233 | 197 | </xsl:stylesheet> |