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