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