3.1 --- a/XSLForms/XSL/PrepareMacro.xsl Wed Nov 30 18:01:12 2005 +0000
3.2 +++ b/XSLForms/XSL/PrepareMacro.xsl Wed Nov 30 18:02:18 2005 +0000
3.3 @@ -1,5 +1,9 @@
3.4 <?xml version="1.0"?>
3.5 <!--
3.6 +A stylesheet which expands the higher-level macro attributes, producing
3.7 +lower-level attributes that can be translated into the final output stylesheet
3.8 +code.
3.9 +
3.10 Copyright (C) 2005 Paul Boddie <paul@boddie.org.uk>
3.11
3.12 This library is free software; you can redistribute it and/or
3.13 @@ -23,6 +27,7 @@
3.14 <xsl:output indent="yes"/>
3.15
3.16 <!-- Input fields. -->
3.17 + <!-- Format: attribute -->
3.18
3.19 <xsl:template match="*[@template:attribute-field]">
3.20 <xsl:copy>
3.21 @@ -36,6 +41,7 @@
3.22 </xsl:template>
3.23
3.24 <!-- Text areas and other elements without value attributes. -->
3.25 + <!-- Format: attribute[,effect] -->
3.26
3.27 <xsl:template match="*[@template:attribute-area]">
3.28 <xsl:variable name="field-attr" select="substring-before(@template:attribute-area, ',')"/>
3.29 @@ -62,6 +68,7 @@
3.30 </xsl:template>
3.31
3.32 <!-- Buttons whose state varies according to an attribute. -->
3.33 + <!-- Format: attribute,value,attribute-to-set -->
3.34
3.35 <xsl:template match="*[@template:attribute-button]">
3.36 <xsl:variable name="field-attr" select="substring-before(@template:attribute-button, ',')"/>
3.37 @@ -81,6 +88,7 @@
3.38 </xsl:template>
3.39
3.40 <!-- Buttons whose state varies according to an attribute in a list of multiple choice elements. -->
3.41 + <!-- Format: attribute,attribute-to-set -->
3.42
3.43 <xsl:template match="*[@template:attribute-list-button]">
3.44 <xsl:variable name="field-attr" select="substring-before(@template:attribute-list-button, ',')"/>
3.45 @@ -98,6 +106,7 @@
3.46 </xsl:template>
3.47
3.48 <!-- Selectors. -->
3.49 + <!-- Format: name[,affected-element] -->
3.50
3.51 <xsl:template match="*[@template:selector-field]">
3.52 <xsl:variable name="field-name" select="substring-before(@template:selector-field, ',')"/>
3.53 @@ -118,6 +127,7 @@
3.54 </xsl:template>
3.55
3.56 <!-- Multiple choice fields, represented by menus and listboxes. -->
3.57 + <!-- Format: element,attribute[,attribute-type] -->
3.58
3.59 <xsl:template match="*[@template:multiple-choice-field]">
3.60 <xsl:variable name="field-element" select="substring-before(@template:multiple-choice-field, ',')"/>
3.61 @@ -148,6 +158,7 @@
3.62 </xsl:template>
3.63
3.64 <!-- Multiple choice list fields, represented by menus and listboxes with multiple values. -->
3.65 + <!-- Format: element,list-element,list-attribute -->
3.66
3.67 <xsl:template match="*[@template:multiple-choice-list-field]">
3.68 <xsl:variable name="field-element" select="substring-before(@template:multiple-choice-list-field, ',')"/>
3.69 @@ -167,44 +178,73 @@
3.70 </xsl:template>
3.71
3.72 <!-- Multiple choice values, represented by option elements. -->
3.73 + <!-- Format: element,attribute,attribute-to-set[,contents-expr] -->
3.74
3.75 <xsl:template match="*[@template:multiple-choice-value]">
3.76 <xsl:variable name="field-element" select="substring-before(@template:multiple-choice-value, ',')"/>
3.77 <xsl:variable name="field-attr-info" select="substring-after(@template:multiple-choice-value, ',')"/>
3.78 <xsl:variable name="field-attr" select="substring-before($field-attr-info, ',')"/>
3.79 - <xsl:variable name="field-set-attr" select="substring-after($field-attr-info, ',')"/>
3.80 + <xsl:variable name="field-set-attr-info" select="substring-after($field-attr-info, ',')"/>
3.81 + <xsl:variable name="field-set-attr" select="substring-before($field-set-attr-info, ',')"/>
3.82 + <xsl:variable name="field-contents" select="substring-after($field-set-attr-info, ',')"/>
3.83 <xsl:copy>
3.84 <!-- Remove multiple-choice-value and replace value. -->
3.85 <xsl:apply-templates select="@*[local-name() != 'multiple-choice-value' and local-name() != 'value']"/>
3.86 <xsl:attribute name="template:element"><xsl:value-of select="$field-element"/></xsl:attribute>
3.87 <xsl:attribute name="template:expr">@<xsl:value-of select="$field-attr"/> = ../@<xsl:value-of select="$field-attr"/></xsl:attribute>
3.88 - <xsl:attribute name="template:expr-attr"><xsl:value-of select="$field-set-attr"/></xsl:attribute>
3.89 - <xsl:attribute name="template:value">@<xsl:value-of select="$field-attr"/></xsl:attribute>
3.90 + <!-- For the option text... -->
3.91 + <xsl:choose>
3.92 + <!-- Either provide the stated attribute as the eventual text of an option element. -->
3.93 + <xsl:when test="$field-set-attr = ''">
3.94 + <xsl:attribute name="template:expr-attr"><xsl:value-of select="$field-set-attr-info"/></xsl:attribute>
3.95 + <xsl:attribute name="template:value">@<xsl:value-of select="$field-attr"/></xsl:attribute>
3.96 + </xsl:when>
3.97 + <!-- Or get the specific contents. -->
3.98 + <xsl:otherwise>
3.99 + <xsl:attribute name="template:expr-attr"><xsl:value-of select="$field-set-attr"/></xsl:attribute>
3.100 + <xsl:attribute name="template:value"><xsl:value-of select="$field-contents"/></xsl:attribute>
3.101 + </xsl:otherwise>
3.102 + </xsl:choose>
3.103 <xsl:attribute name="value">{@<xsl:value-of select="$field-attr"/>}</xsl:attribute>
3.104 <xsl:apply-templates select="*|node()"/>
3.105 </xsl:copy>
3.106 </xsl:template>
3.107
3.108 <!-- Multiple choice list values, represented by option elements. -->
3.109 + <!-- Format: list-element,list-attribute,attribute-to-set[,contents-expr] -->
3.110
3.111 <xsl:template match="*[@template:multiple-choice-list-value]">
3.112 <xsl:variable name="field-element" select="substring-before(@template:multiple-choice-list-value, ',')"/>
3.113 <xsl:variable name="field-attr-info" select="substring-after(@template:multiple-choice-list-value, ',')"/>
3.114 <xsl:variable name="field-attr" select="substring-before($field-attr-info, ',')"/>
3.115 - <xsl:variable name="field-set-attr" select="substring-after($field-attr-info, ',')"/>
3.116 + <xsl:variable name="field-set-attr-info" select="substring-after($field-attr-info, ',')"/>
3.117 + <xsl:variable name="field-set-attr" select="substring-before($field-set-attr-info, ',')"/>
3.118 + <xsl:variable name="field-contents" select="substring-after($field-set-attr-info, ',')"/>
3.119 <xsl:copy>
3.120 <!-- Remove multiple-choice-value and replace value. -->
3.121 <xsl:apply-templates select="@*[local-name() != 'multiple-choice-list-value' and local-name() != 'value']"/>
3.122 <xsl:attribute name="template:element"><xsl:value-of select="$field-element"/></xsl:attribute>
3.123 <xsl:attribute name="template:expr">@value-is-set</xsl:attribute>
3.124 - <xsl:attribute name="template:expr-attr"><xsl:value-of select="$field-set-attr"/></xsl:attribute>
3.125 - <xsl:attribute name="template:value">@<xsl:value-of select="$field-attr"/></xsl:attribute>
3.126 + <!-- For the option text... -->
3.127 + <xsl:choose>
3.128 + <!-- Either provide the stated attribute as the eventual text of an option element. -->
3.129 + <xsl:when test="$field-set-attr = ''">
3.130 + <xsl:attribute name="template:expr-attr"><xsl:value-of select="$field-set-attr-info"/></xsl:attribute>
3.131 + <xsl:attribute name="template:value">@<xsl:value-of select="$field-attr"/></xsl:attribute>
3.132 + </xsl:when>
3.133 + <!-- Or get the specific contents. -->
3.134 + <xsl:otherwise>
3.135 + <xsl:attribute name="template:expr-attr"><xsl:value-of select="$field-set-attr"/></xsl:attribute>
3.136 + <xsl:attribute name="template:value"><xsl:value-of select="$field-contents"/></xsl:attribute>
3.137 + </xsl:otherwise>
3.138 + </xsl:choose>
3.139 <xsl:attribute name="value">{@<xsl:value-of select="$field-attr"/>}</xsl:attribute>
3.140 <xsl:apply-templates select="*|node()"/>
3.141 </xsl:copy>
3.142 </xsl:template>
3.143
3.144 <!-- Multiple choice elements. -->
3.145 + <!-- Format: element,list-element,list-attribute -->
3.146
3.147 <xsl:template match="*[@template:multiple-choice-list-element]">
3.148 <xsl:variable name="element" select="substring-before(@template:multiple-choice-list-element, ',')"/>