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