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@233 | 8 | <xsl:template match="*[@template:attribute-field]"> |
paulb@233 | 9 | <xsl:copy> |
paulb@237 | 10 | <!-- Remove attribute-field and replace name and value. --> |
paulb@237 | 11 | <xsl:apply-templates select="@*[local-name() != 'attribute-field' and local-name() != 'name' and local-name() != 'value']"/> |
paulb@233 | 12 | <xsl:attribute name="template:attribute"><xsl:value-of select="@template:attribute-field"/></xsl:attribute> |
paulb@233 | 13 | <xsl:attribute name="name">{template:this-attribute()}</xsl:attribute> |
paulb@233 | 14 | <xsl:attribute name="value">{$this-value}</xsl:attribute> |
paulb@233 | 15 | <xsl:apply-templates select="*|node()"/> |
paulb@233 | 16 | </xsl:copy> |
paulb@233 | 17 | </xsl:template> |
paulb@233 | 18 | |
paulb@254 | 19 | <xsl:template match="*[@template:attribute-button]"> |
paulb@254 | 20 | <xsl:variable name="field-attr" select="substring-before(@template:attribute-button, ',')"/> |
paulb@254 | 21 | <xsl:variable name="field-set-attr" select="substring-after(@template:attribute-button, ',')"/> |
paulb@254 | 22 | <xsl:copy> |
paulb@254 | 23 | <!-- Remove attribute-button and replace name. --> |
paulb@254 | 24 | <xsl:apply-templates select="@*[local-name() != 'attribute-button' and local-name() != 'name']"/> |
paulb@254 | 25 | <xsl:attribute name="template:attribute"><xsl:value-of select="$field-attr"/></xsl:attribute> |
paulb@254 | 26 | <xsl:attribute name="template:expr-attr"><xsl:value-of select="$field-set-attr"/></xsl:attribute> |
paulb@254 | 27 | <xsl:attribute name="template:expr">$this-value != ''</xsl:attribute> |
paulb@254 | 28 | <xsl:attribute name="name">{template:this-attribute()}</xsl:attribute> |
paulb@254 | 29 | <xsl:apply-templates select="*|node()"/> |
paulb@254 | 30 | </xsl:copy> |
paulb@254 | 31 | </xsl:template> |
paulb@254 | 32 | |
paulb@233 | 33 | <xsl:template match="*[@template:selector-field]"> |
paulb@233 | 34 | <xsl:variable name="field-name" select="@template:selector-field"/> |
paulb@233 | 35 | <xsl:copy> |
paulb@237 | 36 | <!-- Remove selector-field and replace name. --> |
paulb@237 | 37 | <xsl:apply-templates select="@*[local-name() != 'selector-field' and local-name() != 'name']"/> |
paulb@233 | 38 | <xsl:attribute name="name"><xsl:value-of select="$field-name"/>={template:this-element()}</xsl:attribute> |
paulb@233 | 39 | <xsl:apply-templates select="*|node()"/> |
paulb@233 | 40 | </xsl:copy> |
paulb@233 | 41 | </xsl:template> |
paulb@233 | 42 | |
paulb@233 | 43 | <xsl:template match="*[@template:multiple-choice-field]"> |
paulb@233 | 44 | <xsl:variable name="field-element" select="substring-before(@template:multiple-choice-field, ',')"/> |
paulb@233 | 45 | <xsl:variable name="field-attr" select="substring-after(@template:multiple-choice-field, ',')"/> |
paulb@233 | 46 | <xsl:copy> |
paulb@237 | 47 | <!-- Remove multiple-choice-field and replace name. --> |
paulb@237 | 48 | <xsl:apply-templates select="@*[local-name() != 'multiple-choice-field' and local-name() != 'name']"/> |
paulb@233 | 49 | <xsl:attribute name="template:element"><xsl:value-of select="$field-element"/></xsl:attribute> |
paulb@233 | 50 | <xsl:attribute name="name">{template:new-attribute('<xsl:value-of select="$field-attr"/>')}</xsl:attribute> |
paulb@233 | 51 | <xsl:apply-templates select="*|node()"/> |
paulb@233 | 52 | </xsl:copy> |
paulb@233 | 53 | </xsl:template> |
paulb@233 | 54 | |
paulb@233 | 55 | <xsl:template match="*[@template:multiple-choice-value]"> |
paulb@233 | 56 | <xsl:variable name="field-element" select="substring-before(@template:multiple-choice-value, ',')"/> |
paulb@233 | 57 | <xsl:variable name="field-attr-info" select="substring-after(@template:multiple-choice-value, ',')"/> |
paulb@233 | 58 | <xsl:variable name="field-attr" select="substring-before($field-attr-info, ',')"/> |
paulb@233 | 59 | <xsl:variable name="field-set-attr" select="substring-after($field-attr-info, ',')"/> |
paulb@233 | 60 | <xsl:copy> |
paulb@237 | 61 | <!-- Remove multiple-choice-value and replace value. --> |
paulb@237 | 62 | <xsl:apply-templates select="@*[local-name() != 'multiple-choice-value' and local-name() != 'value']"/> |
paulb@233 | 63 | <xsl:attribute name="template:element"><xsl:value-of select="$field-element"/></xsl:attribute> |
paulb@233 | 64 | <xsl:attribute name="template:expr">@<xsl:value-of select="$field-attr"/> = ../@<xsl:value-of select="$field-attr"/></xsl:attribute> |
paulb@233 | 65 | <xsl:attribute name="template:expr-attr"><xsl:value-of select="$field-set-attr"/></xsl:attribute> |
paulb@233 | 66 | <xsl:attribute name="template:value">@<xsl:value-of select="$field-attr"/></xsl:attribute> |
paulb@233 | 67 | <xsl:attribute name="value">{@<xsl:value-of select="$field-attr"/>}</xsl:attribute> |
paulb@233 | 68 | <xsl:apply-templates select="*|node()"/> |
paulb@233 | 69 | </xsl:copy> |
paulb@233 | 70 | </xsl:template> |
paulb@233 | 71 | |
paulb@233 | 72 | <!-- Replicate unknown elements. --> |
paulb@233 | 73 | |
paulb@233 | 74 | <xsl:template match="@*|node()"> |
paulb@233 | 75 | <xsl:copy> |
paulb@233 | 76 | <xsl:apply-templates select="@*|node()"/> |
paulb@233 | 77 | </xsl:copy> |
paulb@233 | 78 | </xsl:template> |
paulb@233 | 79 | |
paulb@233 | 80 | </xsl:stylesheet> |