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