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