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:selector-field]"> 20 <xsl:variable name="field-name" select="@template:selector-field"/> 21 <xsl:copy> 22 <!-- Remove selector-field and replace name. --> 23 <xsl:apply-templates select="@*[local-name() != 'selector-field' and local-name() != 'name']"/> 24 <xsl:attribute name="name"><xsl:value-of select="$field-name"/>={template:this-element()}</xsl:attribute> 25 <xsl:apply-templates select="*|node()"/> 26 </xsl:copy> 27 </xsl:template> 28 29 <xsl:template match="*[@template:multiple-choice-field]"> 30 <xsl:variable name="field-element" select="substring-before(@template:multiple-choice-field, ',')"/> 31 <xsl:variable name="field-attr" select="substring-after(@template:multiple-choice-field, ',')"/> 32 <xsl:copy> 33 <!-- Remove multiple-choice-field and replace name. --> 34 <xsl:apply-templates select="@*[local-name() != 'multiple-choice-field' and local-name() != 'name']"/> 35 <xsl:attribute name="template:element"><xsl:value-of select="$field-element"/></xsl:attribute> 36 <xsl:attribute name="name">{template:new-attribute('<xsl:value-of select="$field-attr"/>')}</xsl:attribute> 37 <xsl:apply-templates select="*|node()"/> 38 </xsl:copy> 39 </xsl:template> 40 41 <xsl:template match="*[@template:multiple-choice-value]"> 42 <xsl:variable name="field-element" select="substring-before(@template:multiple-choice-value, ',')"/> 43 <xsl:variable name="field-attr-info" select="substring-after(@template:multiple-choice-value, ',')"/> 44 <xsl:variable name="field-attr" select="substring-before($field-attr-info, ',')"/> 45 <xsl:variable name="field-set-attr" select="substring-after($field-attr-info, ',')"/> 46 <xsl:copy> 47 <!-- Remove multiple-choice-value and replace value. --> 48 <xsl:apply-templates select="@*[local-name() != 'multiple-choice-value' and local-name() != 'value']"/> 49 <xsl:attribute name="template:element"><xsl:value-of select="$field-element"/></xsl:attribute> 50 <xsl:attribute name="template:expr">@<xsl:value-of select="$field-attr"/> = ../@<xsl:value-of select="$field-attr"/></xsl:attribute> 51 <xsl:attribute name="template:expr-attr"><xsl:value-of select="$field-set-attr"/></xsl:attribute> 52 <xsl:attribute name="template:value">@<xsl:value-of select="$field-attr"/></xsl:attribute> 53 <xsl:attribute name="value">{@<xsl:value-of select="$field-attr"/>}</xsl:attribute> 54 <xsl:apply-templates select="*|node()"/> 55 </xsl:copy> 56 </xsl:template> 57 58 <!-- Replicate unknown elements. --> 59 60 <xsl:template match="@*|node()"> 61 <xsl:copy> 62 <xsl:apply-templates select="@*|node()"/> 63 </xsl:copy> 64 </xsl:template> 65 66 </xsl:stylesheet>