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