1.1 --- a/XSLForms/XSL/PrepareMacro.xsl Wed Nov 30 18:01:12 2005 +0000
1.2 +++ b/XSLForms/XSL/PrepareMacro.xsl Wed Nov 30 18:02:18 2005 +0000
1.3 @@ -1,5 +1,9 @@
1.4 <?xml version="1.0"?>
1.5 <!--
1.6 +A stylesheet which expands the higher-level macro attributes, producing
1.7 +lower-level attributes that can be translated into the final output stylesheet
1.8 +code.
1.9 +
1.10 Copyright (C) 2005 Paul Boddie <paul@boddie.org.uk>
1.11
1.12 This library is free software; you can redistribute it and/or
1.13 @@ -23,6 +27,7 @@
1.14 <xsl:output indent="yes"/>
1.15
1.16 <!-- Input fields. -->
1.17 + <!-- Format: attribute -->
1.18
1.19 <xsl:template match="*[@template:attribute-field]">
1.20 <xsl:copy>
1.21 @@ -36,6 +41,7 @@
1.22 </xsl:template>
1.23
1.24 <!-- Text areas and other elements without value attributes. -->
1.25 + <!-- Format: attribute[,effect] -->
1.26
1.27 <xsl:template match="*[@template:attribute-area]">
1.28 <xsl:variable name="field-attr" select="substring-before(@template:attribute-area, ',')"/>
1.29 @@ -62,6 +68,7 @@
1.30 </xsl:template>
1.31
1.32 <!-- Buttons whose state varies according to an attribute. -->
1.33 + <!-- Format: attribute,value,attribute-to-set -->
1.34
1.35 <xsl:template match="*[@template:attribute-button]">
1.36 <xsl:variable name="field-attr" select="substring-before(@template:attribute-button, ',')"/>
1.37 @@ -81,6 +88,7 @@
1.38 </xsl:template>
1.39
1.40 <!-- Buttons whose state varies according to an attribute in a list of multiple choice elements. -->
1.41 + <!-- Format: attribute,attribute-to-set -->
1.42
1.43 <xsl:template match="*[@template:attribute-list-button]">
1.44 <xsl:variable name="field-attr" select="substring-before(@template:attribute-list-button, ',')"/>
1.45 @@ -98,6 +106,7 @@
1.46 </xsl:template>
1.47
1.48 <!-- Selectors. -->
1.49 + <!-- Format: name[,affected-element] -->
1.50
1.51 <xsl:template match="*[@template:selector-field]">
1.52 <xsl:variable name="field-name" select="substring-before(@template:selector-field, ',')"/>
1.53 @@ -118,6 +127,7 @@
1.54 </xsl:template>
1.55
1.56 <!-- Multiple choice fields, represented by menus and listboxes. -->
1.57 + <!-- Format: element,attribute[,attribute-type] -->
1.58
1.59 <xsl:template match="*[@template:multiple-choice-field]">
1.60 <xsl:variable name="field-element" select="substring-before(@template:multiple-choice-field, ',')"/>
1.61 @@ -148,6 +158,7 @@
1.62 </xsl:template>
1.63
1.64 <!-- Multiple choice list fields, represented by menus and listboxes with multiple values. -->
1.65 + <!-- Format: element,list-element,list-attribute -->
1.66
1.67 <xsl:template match="*[@template:multiple-choice-list-field]">
1.68 <xsl:variable name="field-element" select="substring-before(@template:multiple-choice-list-field, ',')"/>
1.69 @@ -167,44 +178,73 @@
1.70 </xsl:template>
1.71
1.72 <!-- Multiple choice values, represented by option elements. -->
1.73 + <!-- Format: element,attribute,attribute-to-set[,contents-expr] -->
1.74
1.75 <xsl:template match="*[@template:multiple-choice-value]">
1.76 <xsl:variable name="field-element" select="substring-before(@template:multiple-choice-value, ',')"/>
1.77 <xsl:variable name="field-attr-info" select="substring-after(@template:multiple-choice-value, ',')"/>
1.78 <xsl:variable name="field-attr" select="substring-before($field-attr-info, ',')"/>
1.79 - <xsl:variable name="field-set-attr" select="substring-after($field-attr-info, ',')"/>
1.80 + <xsl:variable name="field-set-attr-info" select="substring-after($field-attr-info, ',')"/>
1.81 + <xsl:variable name="field-set-attr" select="substring-before($field-set-attr-info, ',')"/>
1.82 + <xsl:variable name="field-contents" select="substring-after($field-set-attr-info, ',')"/>
1.83 <xsl:copy>
1.84 <!-- Remove multiple-choice-value and replace value. -->
1.85 <xsl:apply-templates select="@*[local-name() != 'multiple-choice-value' and local-name() != 'value']"/>
1.86 <xsl:attribute name="template:element"><xsl:value-of select="$field-element"/></xsl:attribute>
1.87 <xsl:attribute name="template:expr">@<xsl:value-of select="$field-attr"/> = ../@<xsl:value-of select="$field-attr"/></xsl:attribute>
1.88 - <xsl:attribute name="template:expr-attr"><xsl:value-of select="$field-set-attr"/></xsl:attribute>
1.89 - <xsl:attribute name="template:value">@<xsl:value-of select="$field-attr"/></xsl:attribute>
1.90 + <!-- For the option text... -->
1.91 + <xsl:choose>
1.92 + <!-- Either provide the stated attribute as the eventual text of an option element. -->
1.93 + <xsl:when test="$field-set-attr = ''">
1.94 + <xsl:attribute name="template:expr-attr"><xsl:value-of select="$field-set-attr-info"/></xsl:attribute>
1.95 + <xsl:attribute name="template:value">@<xsl:value-of select="$field-attr"/></xsl:attribute>
1.96 + </xsl:when>
1.97 + <!-- Or get the specific contents. -->
1.98 + <xsl:otherwise>
1.99 + <xsl:attribute name="template:expr-attr"><xsl:value-of select="$field-set-attr"/></xsl:attribute>
1.100 + <xsl:attribute name="template:value"><xsl:value-of select="$field-contents"/></xsl:attribute>
1.101 + </xsl:otherwise>
1.102 + </xsl:choose>
1.103 <xsl:attribute name="value">{@<xsl:value-of select="$field-attr"/>}</xsl:attribute>
1.104 <xsl:apply-templates select="*|node()"/>
1.105 </xsl:copy>
1.106 </xsl:template>
1.107
1.108 <!-- Multiple choice list values, represented by option elements. -->
1.109 + <!-- Format: list-element,list-attribute,attribute-to-set[,contents-expr] -->
1.110
1.111 <xsl:template match="*[@template:multiple-choice-list-value]">
1.112 <xsl:variable name="field-element" select="substring-before(@template:multiple-choice-list-value, ',')"/>
1.113 <xsl:variable name="field-attr-info" select="substring-after(@template:multiple-choice-list-value, ',')"/>
1.114 <xsl:variable name="field-attr" select="substring-before($field-attr-info, ',')"/>
1.115 - <xsl:variable name="field-set-attr" select="substring-after($field-attr-info, ',')"/>
1.116 + <xsl:variable name="field-set-attr-info" select="substring-after($field-attr-info, ',')"/>
1.117 + <xsl:variable name="field-set-attr" select="substring-before($field-set-attr-info, ',')"/>
1.118 + <xsl:variable name="field-contents" select="substring-after($field-set-attr-info, ',')"/>
1.119 <xsl:copy>
1.120 <!-- Remove multiple-choice-value and replace value. -->
1.121 <xsl:apply-templates select="@*[local-name() != 'multiple-choice-list-value' and local-name() != 'value']"/>
1.122 <xsl:attribute name="template:element"><xsl:value-of select="$field-element"/></xsl:attribute>
1.123 <xsl:attribute name="template:expr">@value-is-set</xsl:attribute>
1.124 - <xsl:attribute name="template:expr-attr"><xsl:value-of select="$field-set-attr"/></xsl:attribute>
1.125 - <xsl:attribute name="template:value">@<xsl:value-of select="$field-attr"/></xsl:attribute>
1.126 + <!-- For the option text... -->
1.127 + <xsl:choose>
1.128 + <!-- Either provide the stated attribute as the eventual text of an option element. -->
1.129 + <xsl:when test="$field-set-attr = ''">
1.130 + <xsl:attribute name="template:expr-attr"><xsl:value-of select="$field-set-attr-info"/></xsl:attribute>
1.131 + <xsl:attribute name="template:value">@<xsl:value-of select="$field-attr"/></xsl:attribute>
1.132 + </xsl:when>
1.133 + <!-- Or get the specific contents. -->
1.134 + <xsl:otherwise>
1.135 + <xsl:attribute name="template:expr-attr"><xsl:value-of select="$field-set-attr"/></xsl:attribute>
1.136 + <xsl:attribute name="template:value"><xsl:value-of select="$field-contents"/></xsl:attribute>
1.137 + </xsl:otherwise>
1.138 + </xsl:choose>
1.139 <xsl:attribute name="value">{@<xsl:value-of select="$field-attr"/>}</xsl:attribute>
1.140 <xsl:apply-templates select="*|node()"/>
1.141 </xsl:copy>
1.142 </xsl:template>
1.143
1.144 <!-- Multiple choice elements. -->
1.145 + <!-- Format: element,list-element,list-attribute -->
1.146
1.147 <xsl:template match="*[@template:multiple-choice-list-element]">
1.148 <xsl:variable name="element" select="substring-before(@template:multiple-choice-list-element, ',')"/>