paulb@233 | 1 | <?xml version="1.0"?> |
paulb@233 | 2 | <xsl:stylesheet version="1.0" |
paulb@233 | 3 | xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
paulb@233 | 4 | xmlns:template="http://www.boddie.org.uk/ns/xmltools/template"> |
paulb@233 | 5 | |
paulb@233 | 6 | <xsl:output indent="yes"/> |
paulb@233 | 7 | |
paulb@258 | 8 | <!-- Input fields. --> |
paulb@258 | 9 | |
paulb@233 | 10 | <xsl:template match="*[@template:attribute-field]"> |
paulb@233 | 11 | <xsl:copy> |
paulb@237 | 12 | <!-- Remove attribute-field and replace name and value. --> |
paulb@237 | 13 | <xsl:apply-templates select="@*[local-name() != 'attribute-field' and local-name() != 'name' and local-name() != 'value']"/> |
paulb@233 | 14 | <xsl:attribute name="template:attribute"><xsl:value-of select="@template:attribute-field"/></xsl:attribute> |
paulb@233 | 15 | <xsl:attribute name="name">{template:this-attribute()}</xsl:attribute> |
paulb@233 | 16 | <xsl:attribute name="value">{$this-value}</xsl:attribute> |
paulb@233 | 17 | <xsl:apply-templates select="*|node()"/> |
paulb@233 | 18 | </xsl:copy> |
paulb@233 | 19 | </xsl:template> |
paulb@233 | 20 | |
paulb@258 | 21 | <!-- Text areas and other elements without value attributes. --> |
paulb@258 | 22 | |
paulb@258 | 23 | <xsl:template match="*[@template:attribute-area]"> |
paulb@262 | 24 | <xsl:variable name="field-attr" select="substring-before(@template:attribute-area, ',')"/> |
paulb@262 | 25 | <xsl:variable name="field-effect" select="substring-after(@template:attribute-area, ',')"/> |
paulb@258 | 26 | <xsl:copy> |
paulb@262 | 27 | <!-- Remove attribute-area and replace name. --> |
paulb@262 | 28 | <xsl:apply-templates select="@*[local-name() != 'attribute-area' and local-name() != 'name']"/> |
paulb@262 | 29 | <xsl:choose> |
paulb@262 | 30 | <xsl:when test="$field-attr != ''"> |
paulb@262 | 31 | <xsl:attribute name="template:attribute"><xsl:value-of select="$field-attr"/></xsl:attribute> |
paulb@262 | 32 | <xsl:if test="$field-effect != ''"> |
paulb@262 | 33 | <xsl:attribute name="template:effect"><xsl:value-of select="$field-effect"/></xsl:attribute> |
paulb@262 | 34 | <xsl:attribute name="template:value">$this-value</xsl:attribute> |
paulb@262 | 35 | </xsl:if> |
paulb@262 | 36 | </xsl:when> |
paulb@262 | 37 | <xsl:otherwise> |
paulb@262 | 38 | <xsl:attribute name="template:attribute"><xsl:value-of select="@template:attribute-area"/></xsl:attribute> |
paulb@262 | 39 | </xsl:otherwise> |
paulb@262 | 40 | </xsl:choose> |
paulb@258 | 41 | <xsl:attribute name="name">{template:this-attribute()}</xsl:attribute> |
paulb@258 | 42 | <xsl:apply-templates select="*|node()"/> |
paulb@258 | 43 | </xsl:copy> |
paulb@258 | 44 | </xsl:template> |
paulb@258 | 45 | |
paulb@258 | 46 | <!-- Buttons whose state varies according to an attribute. --> |
paulb@258 | 47 | |
paulb@254 | 48 | <xsl:template match="*[@template:attribute-button]"> |
paulb@254 | 49 | <xsl:variable name="field-attr" select="substring-before(@template:attribute-button, ',')"/> |
paulb@262 | 50 | <xsl:variable name="field-info" select="substring-after(@template:attribute-button, ',')"/> |
paulb@262 | 51 | <xsl:variable name="field-value" select="substring-before($field-info, ',')"/> |
paulb@262 | 52 | <xsl:variable name="field-set-attr" select="substring-after($field-info, ',')"/> |
paulb@254 | 53 | <xsl:copy> |
paulb@254 | 54 | <!-- Remove attribute-button and replace name. --> |
paulb@254 | 55 | <xsl:apply-templates select="@*[local-name() != 'attribute-button' and local-name() != 'name']"/> |
paulb@254 | 56 | <xsl:attribute name="template:attribute"><xsl:value-of select="$field-attr"/></xsl:attribute> |
paulb@254 | 57 | <xsl:attribute name="template:expr-attr"><xsl:value-of select="$field-set-attr"/></xsl:attribute> |
paulb@262 | 58 | <xsl:attribute name="template:expr">$this-value = '<xsl:value-of select="$field-value"/>'</xsl:attribute> |
paulb@254 | 59 | <xsl:attribute name="name">{template:this-attribute()}</xsl:attribute> |
paulb@262 | 60 | <xsl:attribute name="value"><xsl:value-of select="$field-value"/></xsl:attribute> |
paulb@254 | 61 | <xsl:apply-templates select="*|node()"/> |
paulb@254 | 62 | </xsl:copy> |
paulb@254 | 63 | </xsl:template> |
paulb@254 | 64 | |
paulb@258 | 65 | <!-- Selectors. --> |
paulb@258 | 66 | |
paulb@233 | 67 | <xsl:template match="*[@template:selector-field]"> |
paulb@258 | 68 | <xsl:variable name="field-name" select="substring-before(@template:selector-field, ',')"/> |
paulb@258 | 69 | <xsl:variable name="affected-element" select="substring-after(@template:selector-field, ',')"/> |
paulb@233 | 70 | <xsl:copy> |
paulb@237 | 71 | <!-- Remove selector-field and replace name. --> |
paulb@237 | 72 | <xsl:apply-templates select="@*[local-name() != 'selector-field' and local-name() != 'name']"/> |
paulb@258 | 73 | <xsl:choose> |
paulb@258 | 74 | <xsl:when test="$field-name != ''"> |
paulb@258 | 75 | <xsl:attribute name="name"><xsl:value-of select="$field-name"/>={template:this-element()}</xsl:attribute> |
paulb@258 | 76 | </xsl:when> |
paulb@258 | 77 | <xsl:otherwise> |
paulb@258 | 78 | <xsl:attribute name="name"><xsl:value-of select="@template:selector-field"/>={template:this-element()}</xsl:attribute> |
paulb@258 | 79 | </xsl:otherwise> |
paulb@258 | 80 | </xsl:choose> |
paulb@233 | 81 | <xsl:apply-templates select="*|node()"/> |
paulb@233 | 82 | </xsl:copy> |
paulb@233 | 83 | </xsl:template> |
paulb@233 | 84 | |
paulb@258 | 85 | <!-- Multiple choice fields, represented by menus and listboxes. --> |
paulb@258 | 86 | |
paulb@233 | 87 | <xsl:template match="*[@template:multiple-choice-field]"> |
paulb@233 | 88 | <xsl:variable name="field-element" select="substring-before(@template:multiple-choice-field, ',')"/> |
paulb@233 | 89 | <xsl:variable name="field-attr" select="substring-after(@template:multiple-choice-field, ',')"/> |
paulb@233 | 90 | <xsl:copy> |
paulb@237 | 91 | <!-- Remove multiple-choice-field and replace name. --> |
paulb@237 | 92 | <xsl:apply-templates select="@*[local-name() != 'multiple-choice-field' and local-name() != 'name']"/> |
paulb@262 | 93 | <xsl:if test="$field-element != '-'"> |
paulb@262 | 94 | <xsl:attribute name="template:element"><xsl:value-of select="$field-element"/></xsl:attribute> |
paulb@262 | 95 | </xsl:if> |
paulb@233 | 96 | <xsl:attribute name="name">{template:new-attribute('<xsl:value-of select="$field-attr"/>')}</xsl:attribute> |
paulb@233 | 97 | <xsl:apply-templates select="*|node()"/> |
paulb@233 | 98 | </xsl:copy> |
paulb@233 | 99 | </xsl:template> |
paulb@233 | 100 | |
paulb@258 | 101 | <!-- Multiple choice list fields, represented by menus and listboxes with multiple values. --> |
paulb@258 | 102 | |
paulb@258 | 103 | <xsl:template match="*[@template:multiple-choice-list-field]"> |
paulb@258 | 104 | <xsl:variable name="field-element" select="substring-before(@template:multiple-choice-list-field, ',')"/> |
paulb@258 | 105 | <xsl:variable name="field-list-info" select="substring-after(@template:multiple-choice-list-field, ',')"/> |
paulb@258 | 106 | <xsl:variable name="field-list-element" select="substring-before($field-list-info, ',')"/> |
paulb@258 | 107 | <xsl:variable name="field-list-attr" select="substring-after($field-list-info, ',')"/> |
paulb@258 | 108 | <xsl:copy> |
paulb@258 | 109 | <!-- Remove multiple-choice-list-field and replace name. --> |
paulb@258 | 110 | <xsl:apply-templates select="@*[local-name() != 'multiple-choice-list-field' and local-name() != 'name']"/> |
paulb@262 | 111 | <xsl:if test="$field-element != '-'"> |
paulb@262 | 112 | <xsl:attribute name="template:element"><xsl:value-of select="$field-element"/></xsl:attribute> |
paulb@262 | 113 | </xsl:if> |
paulb@258 | 114 | <xsl:attribute name="name">{template:list-attribute('<xsl:value-of select="$field-list-element"/>', |
paulb@258 | 115 | '<xsl:value-of select="$field-list-attr"/>')}</xsl:attribute> |
paulb@258 | 116 | <xsl:apply-templates select="*|node()"/> |
paulb@258 | 117 | </xsl:copy> |
paulb@258 | 118 | </xsl:template> |
paulb@258 | 119 | |
paulb@258 | 120 | <!-- Multiple choice values, represented by option elements. --> |
paulb@258 | 121 | |
paulb@233 | 122 | <xsl:template match="*[@template:multiple-choice-value]"> |
paulb@233 | 123 | <xsl:variable name="field-element" select="substring-before(@template:multiple-choice-value, ',')"/> |
paulb@233 | 124 | <xsl:variable name="field-attr-info" select="substring-after(@template:multiple-choice-value, ',')"/> |
paulb@233 | 125 | <xsl:variable name="field-attr" select="substring-before($field-attr-info, ',')"/> |
paulb@233 | 126 | <xsl:variable name="field-set-attr" select="substring-after($field-attr-info, ',')"/> |
paulb@233 | 127 | <xsl:copy> |
paulb@237 | 128 | <!-- Remove multiple-choice-value and replace value. --> |
paulb@237 | 129 | <xsl:apply-templates select="@*[local-name() != 'multiple-choice-value' and local-name() != 'value']"/> |
paulb@233 | 130 | <xsl:attribute name="template:element"><xsl:value-of select="$field-element"/></xsl:attribute> |
paulb@233 | 131 | <xsl:attribute name="template:expr">@<xsl:value-of select="$field-attr"/> = ../@<xsl:value-of select="$field-attr"/></xsl:attribute> |
paulb@233 | 132 | <xsl:attribute name="template:expr-attr"><xsl:value-of select="$field-set-attr"/></xsl:attribute> |
paulb@233 | 133 | <xsl:attribute name="template:value">@<xsl:value-of select="$field-attr"/></xsl:attribute> |
paulb@233 | 134 | <xsl:attribute name="value">{@<xsl:value-of select="$field-attr"/>}</xsl:attribute> |
paulb@233 | 135 | <xsl:apply-templates select="*|node()"/> |
paulb@233 | 136 | </xsl:copy> |
paulb@233 | 137 | </xsl:template> |
paulb@233 | 138 | |
paulb@258 | 139 | <!-- Multiple choice list values, represented by option elements. --> |
paulb@258 | 140 | |
paulb@258 | 141 | <xsl:template match="*[@template:multiple-choice-list-value]"> |
paulb@258 | 142 | <xsl:variable name="field-element" select="substring-before(@template:multiple-choice-list-value, ',')"/> |
paulb@258 | 143 | <xsl:variable name="field-attr-info" select="substring-after(@template:multiple-choice-list-value, ',')"/> |
paulb@258 | 144 | <xsl:variable name="field-attr" select="substring-before($field-attr-info, ',')"/> |
paulb@258 | 145 | <xsl:variable name="field-set-attr" select="substring-after($field-attr-info, ',')"/> |
paulb@258 | 146 | <xsl:copy> |
paulb@258 | 147 | <!-- Remove multiple-choice-value and replace value. --> |
paulb@258 | 148 | <xsl:apply-templates select="@*[local-name() != 'multiple-choice-list-value' and local-name() != 'value']"/> |
paulb@258 | 149 | <xsl:attribute name="template:element"><xsl:value-of select="$field-element"/></xsl:attribute> |
paulb@258 | 150 | <xsl:attribute name="template:expr">@value-is-set</xsl:attribute> |
paulb@258 | 151 | <xsl:attribute name="template:expr-attr"><xsl:value-of select="$field-set-attr"/></xsl:attribute> |
paulb@258 | 152 | <xsl:attribute name="template:value">@<xsl:value-of select="$field-attr"/></xsl:attribute> |
paulb@258 | 153 | <xsl:attribute name="value">{@<xsl:value-of select="$field-attr"/>}</xsl:attribute> |
paulb@258 | 154 | <xsl:apply-templates select="*|node()"/> |
paulb@258 | 155 | </xsl:copy> |
paulb@258 | 156 | </xsl:template> |
paulb@258 | 157 | |
paulb@233 | 158 | <!-- Replicate unknown elements. --> |
paulb@233 | 159 | |
paulb@233 | 160 | <xsl:template match="@*|node()"> |
paulb@233 | 161 | <xsl:copy> |
paulb@233 | 162 | <xsl:apply-templates select="@*|node()"/> |
paulb@233 | 163 | </xsl:copy> |
paulb@233 | 164 | </xsl:template> |
paulb@233 | 165 | |
paulb@233 | 166 | </xsl:stylesheet> |