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@233 | 25 | |
paulb@233 | 26 | |
paulb@233 | 27 | <!-- Match the document itself. --> |
paulb@233 | 28 | |
paulb@233 | 29 | <xsl:template match="/"> |
paulb@233 | 30 | <!-- Process the elements. --> |
paulb@233 | 31 | <xsl:apply-templates select="*"/> |
paulb@233 | 32 | </xsl:template> |
paulb@233 | 33 | |
paulb@233 | 34 | |
paulb@233 | 35 | |
paulb@233 | 36 | <!-- Match element references. --> |
paulb@233 | 37 | |
paulb@233 | 38 | <xsl:template match="*[@template:element]"> |
paulb@233 | 39 | <xsl:call-template name="enter-element"> |
paulb@233 | 40 | <xsl:with-param name="other-elements" select="@template:element"/> |
paulb@233 | 41 | </xsl:call-template> |
paulb@233 | 42 | </xsl:template> |
paulb@233 | 43 | |
paulb@233 | 44 | <xsl:template name="enter-element"> |
paulb@233 | 45 | <xsl:param name="other-elements"/> |
paulb@233 | 46 | <xsl:variable name="first-element" select="substring-before($other-elements, ',')"/> |
paulb@233 | 47 | <xsl:variable name="remaining-elements" select="substring-after($other-elements, ',')"/> |
paulb@233 | 48 | <xsl:choose> |
paulb@233 | 49 | <xsl:when test="$first-element = ''"> |
paulb@233 | 50 | <xsl:call-template name="next-element"> |
paulb@233 | 51 | <xsl:with-param name="first-element" select="$other-elements"/> |
paulb@233 | 52 | </xsl:call-template> |
paulb@233 | 53 | </xsl:when> |
paulb@233 | 54 | <xsl:otherwise> |
paulb@233 | 55 | <xsl:call-template name="next-element"> |
paulb@233 | 56 | <xsl:with-param name="first-element" select="$first-element"/> |
paulb@233 | 57 | <xsl:with-param name="remaining-elements" select="$remaining-elements"/> |
paulb@233 | 58 | </xsl:call-template> |
paulb@233 | 59 | </xsl:otherwise> |
paulb@233 | 60 | </xsl:choose> |
paulb@233 | 61 | </xsl:template> |
paulb@233 | 62 | |
paulb@233 | 63 | <xsl:template name="next-element"> |
paulb@233 | 64 | <xsl:param name="first-element"/> |
paulb@233 | 65 | <xsl:param name="remaining-elements"/> |
paulb@245 | 66 | <element> |
paulb@233 | 67 | <xsl:attribute name="name"><xsl:value-of select="$first-element"/></xsl:attribute> |
paulb@233 | 68 | <xsl:choose> |
paulb@233 | 69 | <xsl:when test="$remaining-elements = ''"> |
paulb@233 | 70 | <xsl:call-template name="enter-attribute"/> |
paulb@233 | 71 | </xsl:when> |
paulb@233 | 72 | <xsl:otherwise> |
paulb@233 | 73 | <xsl:call-template name="enter-element"> |
paulb@233 | 74 | <xsl:with-param name="other-elements" select="$remaining-elements"/> |
paulb@233 | 75 | </xsl:call-template> |
paulb@233 | 76 | </xsl:otherwise> |
paulb@233 | 77 | </xsl:choose> |
paulb@245 | 78 | </element> |
paulb@233 | 79 | </xsl:template> |
paulb@233 | 80 | |
paulb@233 | 81 | |
paulb@233 | 82 | |
paulb@233 | 83 | <!-- Match attributes. --> |
paulb@233 | 84 | |
paulb@258 | 85 | <xsl:template match="*[not(@template:element) and (@template:attribute or @template:attribute-field or @template:attribute-area or @template:attribute-button or @template:selector-field or @template:multiple-choice-field or @template:multiple-choice-list-field or @template:multiple-choice-value or @template:multiple-choice-list-value)]"> |
paulb@233 | 86 | <xsl:call-template name="enter-attribute"/> |
paulb@233 | 87 | </xsl:template> |
paulb@233 | 88 | |
paulb@233 | 89 | <xsl:template name="enter-attribute"> |
paulb@233 | 90 | <xsl:choose> |
paulb@233 | 91 | <xsl:when test="@template:attribute"> |
paulb@245 | 92 | <attribute> |
paulb@233 | 93 | <xsl:attribute name="name"><xsl:value-of select="@template:attribute"/></xsl:attribute> |
paulb@245 | 94 | </attribute> |
paulb@233 | 95 | </xsl:when> |
paulb@258 | 96 | <xsl:when test="@template:attribute-field"> |
paulb@258 | 97 | <attribute> |
paulb@258 | 98 | <xsl:attribute name="name"><xsl:value-of select="@template:attribute-field"/></xsl:attribute> |
paulb@258 | 99 | </attribute> |
paulb@258 | 100 | </xsl:when> |
paulb@258 | 101 | <xsl:when test="@template:attribute-area"> |
paulb@258 | 102 | <attribute> |
paulb@258 | 103 | <xsl:attribute name="name"><xsl:value-of select="@template:attribute-area"/></xsl:attribute> |
paulb@258 | 104 | </attribute> |
paulb@258 | 105 | </xsl:when> |
paulb@258 | 106 | <xsl:when test="@template:attribute-button"> |
paulb@258 | 107 | <attribute> |
paulb@258 | 108 | <xsl:variable name="field-attr" select="substring-before(@template:attribute-button, ',')"/> |
paulb@258 | 109 | <xsl:attribute name="name"><xsl:value-of select="$field-attr"/></xsl:attribute> |
paulb@258 | 110 | </attribute> |
paulb@258 | 111 | </xsl:when> |
paulb@258 | 112 | <xsl:when test="@template:selector-field"> |
paulb@258 | 113 | <xsl:variable name="field-name" select="substring-before(@template:selector-field, ',')"/> |
paulb@258 | 114 | <xsl:variable name="affected-element" select="substring-after(@template:selector-field, ',')"/> |
paulb@258 | 115 | <selector> |
paulb@258 | 116 | <xsl:choose> |
paulb@258 | 117 | <xsl:when test="$field-name != ''"> |
paulb@258 | 118 | <xsl:attribute name="name"><xsl:value-of select="$field-name"/></xsl:attribute> |
paulb@258 | 119 | <xsl:attribute name="element"><xsl:value-of select="$affected-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"/></xsl:attribute> |
paulb@258 | 123 | </xsl:otherwise> |
paulb@258 | 124 | </xsl:choose> |
paulb@258 | 125 | </selector> |
paulb@258 | 126 | </xsl:when> |
paulb@258 | 127 | <xsl:when test="@template:multiple-choice-field"> |
paulb@262 | 128 | <xsl:variable name="field-element" select="substring-before(@template:multiple-choice-field, ',')"/> |
paulb@262 | 129 | <xsl:variable name="field-attr" select="substring-after(@template:multiple-choice-field, ',')"/> |
paulb@262 | 130 | <xsl:choose> |
paulb@262 | 131 | <xsl:when test="$field-element != '-'"> |
paulb@262 | 132 | <element type="multiple-choice"> |
paulb@262 | 133 | <xsl:attribute name="name"><xsl:value-of select="$field-element"/></xsl:attribute> |
paulb@262 | 134 | <attribute> |
paulb@262 | 135 | <xsl:attribute name="name"><xsl:value-of select="$field-attr"/></xsl:attribute> |
paulb@262 | 136 | </attribute> |
paulb@262 | 137 | <xsl:apply-templates select="*"/> |
paulb@262 | 138 | </element> |
paulb@262 | 139 | </xsl:when> |
paulb@262 | 140 | <xsl:otherwise> |
paulb@262 | 141 | <xsl:attribute name="type">multiple-choice</xsl:attribute> |
paulb@262 | 142 | <attribute> |
paulb@262 | 143 | <xsl:attribute name="name"><xsl:value-of select="$field-attr"/></xsl:attribute> |
paulb@262 | 144 | </attribute> |
paulb@262 | 145 | <xsl:apply-templates select="*"/> |
paulb@262 | 146 | </xsl:otherwise> |
paulb@262 | 147 | </xsl:choose> |
paulb@258 | 148 | </xsl:when> |
paulb@258 | 149 | <xsl:when test="@template:multiple-choice-list-field"> |
paulb@262 | 150 | <xsl:variable name="field-element" select="substring-before(@template:multiple-choice-list-field, ',')"/> |
paulb@262 | 151 | <xsl:variable name="field-list-info" select="substring-after(@template:multiple-choice-list-field, ',')"/> |
paulb@262 | 152 | <xsl:variable name="field-list-element" select="substring-before($field-list-info, ',')"/> |
paulb@262 | 153 | <xsl:variable name="field-list-attr" select="substring-after($field-list-info, ',')"/> |
paulb@262 | 154 | <xsl:choose> |
paulb@262 | 155 | <xsl:when test="$field-element != '-'"> |
paulb@262 | 156 | <element type="multiple-choice-list"> |
paulb@262 | 157 | <xsl:attribute name="name"><xsl:value-of select="$field-element"/></xsl:attribute> |
paulb@262 | 158 | <attribute> |
paulb@262 | 159 | <xsl:attribute name="name"><xsl:value-of select="$field-list-attr"/></xsl:attribute> |
paulb@262 | 160 | </attribute> |
paulb@262 | 161 | <xsl:apply-templates select="*"/> |
paulb@262 | 162 | </element> |
paulb@262 | 163 | </xsl:when> |
paulb@262 | 164 | <xsl:otherwise> |
paulb@262 | 165 | <xsl:attribute name="type">multiple-choice-list</xsl:attribute> |
paulb@262 | 166 | <attribute> |
paulb@262 | 167 | <xsl:attribute name="name"><xsl:value-of select="$field-list-attr"/></xsl:attribute> |
paulb@262 | 168 | </attribute> |
paulb@262 | 169 | <xsl:apply-templates select="*"/> |
paulb@262 | 170 | </xsl:otherwise> |
paulb@262 | 171 | </xsl:choose> |
paulb@258 | 172 | </xsl:when> |
paulb@258 | 173 | <xsl:when test="@template:multiple-choice-value"> |
paulb@258 | 174 | <element type="multiple-choice-value"> |
paulb@258 | 175 | <xsl:variable name="field-element" select="substring-before(@template:multiple-choice-value, ',')"/> |
paulb@258 | 176 | <xsl:variable name="field-attr-info" select="substring-after(@template:multiple-choice-value, ',')"/> |
paulb@258 | 177 | <xsl:variable name="field-attr" select="substring-before($field-attr-info, ',')"/> |
paulb@258 | 178 | <xsl:variable name="field-set-attr" select="substring-after($field-attr-info, ',')"/> |
paulb@258 | 179 | <xsl:attribute name="name"><xsl:value-of select="$field-element"/></xsl:attribute> |
paulb@258 | 180 | <xsl:attribute name="expr">@<xsl:value-of select="$field-attr"/> = ../@<xsl:value-of select="$field-attr"/></xsl:attribute> |
paulb@258 | 181 | <xsl:attribute name="expr-attr"><xsl:value-of select="$field-set-attr"/></xsl:attribute> |
paulb@258 | 182 | <attribute> |
paulb@258 | 183 | <xsl:attribute name="name"><xsl:value-of select="$field-attr"/></xsl:attribute> |
paulb@258 | 184 | </attribute> |
paulb@258 | 185 | </element> |
paulb@258 | 186 | </xsl:when> |
paulb@258 | 187 | <xsl:when test="@template:multiple-choice-list-value"> |
paulb@258 | 188 | <element type="multiple-choice-list-value"> |
paulb@258 | 189 | <xsl:variable name="field-element" select="substring-before(@template:multiple-choice-list-value, ',')"/> |
paulb@258 | 190 | <xsl:variable name="field-attr-info" select="substring-after(@template:multiple-choice-list-value, ',')"/> |
paulb@258 | 191 | <xsl:variable name="field-attr" select="substring-before($field-attr-info, ',')"/> |
paulb@258 | 192 | <xsl:variable name="field-set-attr" select="substring-after($field-attr-info, ',')"/> |
paulb@258 | 193 | <xsl:attribute name="name"><xsl:value-of select="$field-element"/></xsl:attribute> |
paulb@258 | 194 | <xsl:attribute name="expr">@value-is-set</xsl:attribute> |
paulb@258 | 195 | <!-- Special attribute corresponding with the expression. --> |
paulb@258 | 196 | <xsl:attribute name="expr-name">value-is-set</xsl:attribute> |
paulb@258 | 197 | <xsl:attribute name="expr-attr"><xsl:value-of select="$field-set-attr"/></xsl:attribute> |
paulb@258 | 198 | <attribute> |
paulb@258 | 199 | <xsl:attribute name="name"><xsl:value-of select="$field-attr"/></xsl:attribute> |
paulb@258 | 200 | </attribute> |
paulb@258 | 201 | </element> |
paulb@258 | 202 | </xsl:when> |
paulb@233 | 203 | <xsl:otherwise> |
paulb@233 | 204 | <xsl:apply-templates select="*"/> |
paulb@233 | 205 | </xsl:otherwise> |
paulb@233 | 206 | </xsl:choose> |
paulb@233 | 207 | </xsl:template> |
paulb@233 | 208 | |
paulb@233 | 209 | |
paulb@233 | 210 | |
paulb@233 | 211 | <!-- Traverse unknown elements. --> |
paulb@233 | 212 | |
paulb@233 | 213 | <xsl:template match="*"> |
paulb@233 | 214 | <xsl:apply-templates select="*"/> |
paulb@233 | 215 | </xsl:template> |
paulb@233 | 216 | |
paulb@233 | 217 | </xsl:stylesheet> |