1.1 --- a/examples/Common/Configurator/Resources/config_database.xsl Thu Jul 21 16:14:08 2005 +0000
1.2 +++ b/examples/Common/Configurator/Resources/config_database.xsl Thu Jul 21 16:15:19 2005 +0000
1.3 @@ -1,8 +1,5 @@
1.4 <?xml version="1.0" encoding="utf-8"?>
1.5 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
1.6 - xmlns:template="http://www.boddie.org.uk/ns/xmltools/template"
1.7 - xmlns:dyn="http://exslt.org/dynamic"
1.8 - extension-element-prefixes="dyn"
1.9 version="1.0">
1.10
1.11 <xsl:param name="database"/>
1.12 @@ -10,123 +7,125 @@
1.13 <xsl:template match="configuration">
1.14 <xsl:copy>
1.15 <xsl:apply-templates select="@*"/>
1.16 + <!-- Find out some additional information. -->
1.17 + <xsl:variable name="cpu-socket" select="$database/database/base-system/base-system-enum[@value = current()/details/base-system/@value]/@cpu-socket"/>
1.18 + <xsl:variable name="interface" select="$database/database/base-system/base-system-enum[@value = current()/details/base-system/@value]/@interface"/>
1.19 <!-- Complete all multiple choice fields. -->
1.20 <details>
1.21 - <xsl:call-template name="complete-element">
1.22 - <xsl:with-param name="found-element" select="details/base-system[1]"/>
1.23 - <xsl:with-param name="element-name">base-system</xsl:with-param>
1.24 - </xsl:call-template>
1.25 - <xsl:call-template name="complete-element">
1.26 - <xsl:with-param name="found-element" select="details/cpu[1]"/>
1.27 - <xsl:with-param name="control-element" select="details/base-system[1]"/>
1.28 - <xsl:with-param name="element-name">cpu</xsl:with-param>
1.29 - <xsl:with-param name="control-element-name">base-system</xsl:with-param>
1.30 - <xsl:with-param name="control-attribute-name">cpu-socket</xsl:with-param>
1.31 - </xsl:call-template>
1.32 + <base-system>
1.33 + <xsl:variable name="value" select="details/base-system/@value"/>
1.34 + <xsl:attribute name="value"><xsl:value-of select="$value"/></xsl:attribute>
1.35 + <xsl:for-each select="$database/database/base-system/base-system-enum">
1.36 + <xsl:copy>
1.37 + <xsl:apply-templates select="@*"/>
1.38 + <xsl:if test="@value = $value">
1.39 + <xsl:attribute name="value-is-set">true</xsl:attribute>
1.40 + </xsl:if>
1.41 + </xsl:copy>
1.42 + </xsl:for-each>
1.43 + </base-system>
1.44 + <cpu>
1.45 + <xsl:variable name="value" select="details/cpu/@value"/>
1.46 + <xsl:attribute name="value"><xsl:value-of select="$value"/></xsl:attribute>
1.47 + <xsl:for-each select="$database/database/cpu/cpu-enum[@cpu-socket = $cpu-socket or not(@cpu-socket)]">
1.48 + <xsl:copy>
1.49 + <xsl:apply-templates select="@*"/>
1.50 + <xsl:if test="@value = $value">
1.51 + <xsl:attribute name="value-is-set">true</xsl:attribute>
1.52 + </xsl:if>
1.53 + </xsl:copy>
1.54 + </xsl:for-each>
1.55 + </cpu>
1.56 </details>
1.57 <memory>
1.58 <xsl:for-each select="memory/memory-unit">
1.59 - <xsl:call-template name="complete-element">
1.60 - <xsl:with-param name="found-element" select="."/>
1.61 - <xsl:with-param name="element-name">memory-unit</xsl:with-param>
1.62 - </xsl:call-template>
1.63 + <xsl:copy>
1.64 + <xsl:variable name="value" select="@value"/>
1.65 + <xsl:attribute name="value"><xsl:value-of select="$value"/></xsl:attribute>
1.66 + <xsl:for-each select="$database/database/memory-unit/memory-unit-enum">
1.67 + <xsl:copy>
1.68 + <xsl:apply-templates select="@*"/>
1.69 + <xsl:if test="@value = $value">
1.70 + <xsl:attribute name="value-is-set">true</xsl:attribute>
1.71 + </xsl:if>
1.72 + </xsl:copy>
1.73 + </xsl:for-each>
1.74 + </xsl:copy>
1.75 </xsl:for-each>
1.76 </memory>
1.77 <hard-disks>
1.78 <xsl:for-each select="hard-disks/hard-disk">
1.79 - <xsl:call-template name="complete-element">
1.80 - <xsl:with-param name="found-element" select="."/>
1.81 - <xsl:with-param name="control-element" select="/configuration/details/base-system[1]"/>
1.82 - <xsl:with-param name="element-name">hard-disk</xsl:with-param>
1.83 - <xsl:with-param name="control-element-name">base-system</xsl:with-param>
1.84 - <xsl:with-param name="control-attribute-name">interface</xsl:with-param>
1.85 - </xsl:call-template>
1.86 + <xsl:copy>
1.87 + <xsl:variable name="value" select="@value"/>
1.88 + <xsl:attribute name="value"><xsl:value-of select="$value"/></xsl:attribute>
1.89 + <xsl:for-each select="$database/database/hard-disk/hard-disk-enum[@interface = $interface or not(@interface)]">
1.90 + <xsl:copy>
1.91 + <xsl:apply-templates select="@*"/>
1.92 + <xsl:if test="@value = $value">
1.93 + <xsl:attribute name="value-is-set">true</xsl:attribute>
1.94 + </xsl:if>
1.95 + </xsl:copy>
1.96 + </xsl:for-each>
1.97 + </xsl:copy>
1.98 </xsl:for-each>
1.99 </hard-disks>
1.100 <storage>
1.101 <xsl:for-each select="storage/storage-unit">
1.102 - <xsl:call-template name="complete-element">
1.103 - <xsl:with-param name="found-element" select="."/>
1.104 - <xsl:with-param name="element-name">storage-unit</xsl:with-param>
1.105 - </xsl:call-template>
1.106 + <xsl:copy>
1.107 + <xsl:variable name="value" select="@value"/>
1.108 + <xsl:attribute name="value"><xsl:value-of select="$value"/></xsl:attribute>
1.109 + <xsl:for-each select="$database/database/storage-unit/storage-unit-enum">
1.110 + <xsl:copy>
1.111 + <xsl:apply-templates select="@*"/>
1.112 + <xsl:if test="@value = $value">
1.113 + <xsl:attribute name="value-is-set">true</xsl:attribute>
1.114 + </xsl:if>
1.115 + </xsl:copy>
1.116 + </xsl:for-each>
1.117 + </xsl:copy>
1.118 </xsl:for-each>
1.119 </storage>
1.120 <peripherals>
1.121 - <xsl:call-template name="complete-element">
1.122 - <xsl:with-param name="found-element" select="peripherals/keyboard[1]"/>
1.123 - <xsl:with-param name="element-name">keyboard</xsl:with-param>
1.124 - </xsl:call-template>
1.125 - <xsl:call-template name="complete-element">
1.126 - <xsl:with-param name="found-element" select="peripherals/mouse[1]"/>
1.127 - <xsl:with-param name="element-name">mouse</xsl:with-param>
1.128 - </xsl:call-template>
1.129 - <xsl:call-template name="complete-element">
1.130 - <xsl:with-param name="found-element" select="peripherals/screen[1]"/>
1.131 - <xsl:with-param name="element-name">screen</xsl:with-param>
1.132 - </xsl:call-template>
1.133 + <keyboard>
1.134 + <xsl:variable name="value" select="peripherals/keyboard/@value"/>
1.135 + <xsl:attribute name="value"><xsl:value-of select="$value"/></xsl:attribute>
1.136 + <xsl:for-each select="$database/database/keyboard/keyboard-enum">
1.137 + <xsl:copy>
1.138 + <xsl:apply-templates select="@*"/>
1.139 + <xsl:if test="@value = $value">
1.140 + <xsl:attribute name="value-is-set">true</xsl:attribute>
1.141 + </xsl:if>
1.142 + </xsl:copy>
1.143 + </xsl:for-each>
1.144 + </keyboard>
1.145 + <mouse>
1.146 + <xsl:variable name="value" select="peripherals/mouse/@value"/>
1.147 + <xsl:attribute name="value"><xsl:value-of select="$value"/></xsl:attribute>
1.148 + <xsl:for-each select="$database/database/mouse/mouse-enum">
1.149 + <xsl:copy>
1.150 + <xsl:apply-templates select="@*"/>
1.151 + <xsl:if test="@value = $value">
1.152 + <xsl:attribute name="value-is-set">true</xsl:attribute>
1.153 + </xsl:if>
1.154 + </xsl:copy>
1.155 + </xsl:for-each>
1.156 + </mouse>
1.157 + <screen>
1.158 + <xsl:variable name="value" select="peripherals/screen/@value"/>
1.159 + <xsl:attribute name="value"><xsl:value-of select="$value"/></xsl:attribute>
1.160 + <xsl:for-each select="$database/database/screen/screen-enum">
1.161 + <xsl:copy>
1.162 + <xsl:apply-templates select="@*"/>
1.163 + <xsl:if test="@value = $value">
1.164 + <xsl:attribute name="value-is-set">true</xsl:attribute>
1.165 + </xsl:if>
1.166 + </xsl:copy>
1.167 + </xsl:for-each>
1.168 + </screen>
1.169 </peripherals>
1.170 </xsl:copy>
1.171 </xsl:template>
1.172
1.173 - <xsl:template name="complete-element">
1.174 - <!-- Input parameters. -->
1.175 - <xsl:param name="found-element"/>
1.176 - <xsl:param name="control-element"/>
1.177 - <!-- Database parameters. -->
1.178 - <xsl:param name="element-name"/>
1.179 - <xsl:param name="control-element-name"/>
1.180 - <xsl:param name="control-attribute-name"/>
1.181 - <!-- Find the database entries. -->
1.182 - <xsl:variable name="element-enum-name"><xsl:value-of select="$element-name"/>-enum</xsl:variable>
1.183 - <xsl:variable name="control-element-enum-name"><xsl:value-of select="$control-element-name"/>-enum</xsl:variable>
1.184 - <!-- Find whether the input values are set. -->
1.185 - <xsl:variable name="has-set-values" select="$found-element[@value]"/>
1.186 - <xsl:variable name="has-control-values" select="$control-element and $control-element[@value]"/>
1.187 - <!-- Get the database element for the element being prepared. -->
1.188 - <xsl:variable name="database-element" select="$database/database/*[local-name() = $element-name]"/>
1.189 - <!-- Get the database element for the control element. -->
1.190 - <xsl:variable name="database-control-element" select="$database/database/*[local-name() = $control-element-name]"/>
1.191 - <!-- Get the database entries for the control element. -->
1.192 - <xsl:variable name="control-enum-elements" select="$database-control-element/*[local-name() = $control-element-enum-name]"/>
1.193 - <!-- Get the database entry for the control element, then get the control attribute value in that entry. -->
1.194 - <xsl:variable name="other-control-value" select="$control-enum-elements[@value = $control-element/@value]/@*[local-name() = $control-attribute-name]"/>
1.195 - <!-- Make the element with the different values. -->
1.196 - <xsl:element name="{$element-name}">
1.197 - <!-- Find the entries in the database for the element being prepared. -->
1.198 - <xsl:for-each select="$database-element/*[local-name() = $element-enum-name]">
1.199 - <!-- Remember the current node for future comparisons. -->
1.200 - <xsl:variable name="enum-element" select="."/>
1.201 - <!-- Find whether the current entry matches the input value. -->
1.202 - <xsl:variable name="matching-element" select="$found-element[@value = $enum-element/@value]"/>
1.203 - <!-- Get the control attribute value for the current entry. -->
1.204 - <xsl:variable name="this-control-value" select="@*[local-name() = $control-attribute-name]"/>
1.205 - <!-- Filter the entry out unless no control element was given, this entry has no control attribute value or...
1.206 - if the control attribute value matches the one for the control element. -->
1.207 - <xsl:if test="not($has-control-values) or not($this-control-value) or $this-control-value = $other-control-value">
1.208 - <!-- Copy the entry. -->
1.209 - <xsl:copy>
1.210 - <!-- Include all attributes except the price, adding the price only if the item is selected. -->
1.211 - <xsl:apply-templates select="@*[local-name() != 'price']"/>
1.212 - <!-- Find whether this item is selected. -->
1.213 - <xsl:choose>
1.214 - <!-- In the current field, the value attribute matches this value. -->
1.215 - <xsl:when test="$matching-element">
1.216 - <xsl:attribute name="value-is-set">true</xsl:attribute>
1.217 - <xsl:apply-templates select="@price"/>
1.218 - </xsl:when>
1.219 - <!-- This value is the first and no value attribute is specified. -->
1.220 - <xsl:when test="not($has-set-values) and count($enum-element/preceding-sibling::*) = 0">
1.221 - <xsl:attribute name="value-is-set">true</xsl:attribute>
1.222 - <xsl:apply-templates select="@price"/>
1.223 - </xsl:when>
1.224 - <xsl:otherwise/>
1.225 - </xsl:choose>
1.226 - </xsl:copy>
1.227 - </xsl:if>
1.228 - </xsl:for-each>
1.229 - </xsl:element>
1.230 - </xsl:template>
1.231 -
1.232 <!-- Replicate unknown elements. -->
1.233
1.234 <xsl:template match="@*|node()">
2.1 --- a/examples/Common/Configurator/Resources/config_template.xhtml Thu Jul 21 16:14:08 2005 +0000
2.2 +++ b/examples/Common/Configurator/Resources/config_template.xhtml Thu Jul 21 16:15:19 2005 +0000
2.3 @@ -17,118 +17,123 @@
2.4 <form method="post" action="" template:element="configuration">
2.5 <div id="left">
2.6 <div template:element="details" class="details">
2.7 - <h2>Base System</h2>
2.8 + <h2>Base System</h2>
2.9
2.10 - <p template:element="base-system">Model
2.11 - <select name="{template:list-attribute('value')}" onchange="requestUpdate('{$application-url}cpu', '{template:list-attribute('value')}', '{template:other-nodes(../cpu)}', '{template:other-list-attributes('value', ../cpu)}', '/configuration/details/cpu'); requestUpdate('{$application-url}memory', '{template:list-attribute('value')}', '{template:other-nodes(../../memory)}', '{template:other-list-attributes('value', ../../memory/memory-unit)}', '/configuration/memory'); requestUpdate('{$application-url}hard-disks', '{template:list-attribute('value')}', '{template:other-nodes(../../hard-disks)}', '{template:other-list-attributes('value', ../../hard-disks/hard-disk)}', '/configuration/hard-disks')">
2.12 - <option template:element="base-system-enum" template:expr="@value-is-set" template:expr-attr="selected" template:value="@value"
2.13 - value="{@value}"></option>
2.14 - </select>
2.15 - </p>
2.16 + <p template:element="base-system">Model
2.17 + <select template:attribute="value" name="{template:this-attribute()}" onchange="requestUpdate('{$application-url}cpu', '{template:this-attribute()}', '{template:other-elements(../cpu)}', '{template:other-attributes('value', ../cpu)}', '/configuration/details/cpu'); requestUpdate('{$application-url}memory', '{template:this-attribute()}', '{template:other-elements(../../memory)}', '{template:other-attributes('value', ../../memory/memory-unit)}', '/configuration/memory'); requestUpdate('{$application-url}hard-disks', '{template:this-attribute()}', '{template:other-elements(../../hard-disks)}', '{template:other-attributes('value', ../../hard-disks/hard-disk)}', '/configuration/hard-disks')">
2.18 + <option template:element="base-system-enum" template:expr="@value-is-set" template:expr-attr="selected" template:value="@value"
2.19 + value="{@value}"></option>
2.20 + </select>
2.21 + </p>
2.22
2.23 - <h2>Processor</h2>
2.24 + <h2>Processor</h2>
2.25
2.26 - <p template:element="cpu">CPU
2.27 - <select template:id="cpu-node" id="{template:this-element()}" name="{template:list-attribute('value')}">
2.28 - <option template:element="cpu-enum" template:expr="@value-is-set" template:expr-attr="selected" template:value="@value"
2.29 - value="{@value}"></option>
2.30 - </select>
2.31 - </p>
2.32 + <p template:element="cpu" template:id="cpu-node" id="{template:this-element()}">CPU
2.33 + <select template:attribute="value" name="{template:this-attribute()}">
2.34 + <option template:element="cpu-enum" template:expr="@value-is-set" template:expr-attr="selected" template:value="@value"
2.35 + value="{@value}"></option>
2.36 + </select>
2.37 + </p>
2.38 </div>
2.39
2.40 - <div template:element="memory" class="memory">
2.41 - <h2>Memory</h2>
2.42 + <div class="memory" template:element="memory">
2.43 + <h2>Memory</h2>
2.44
2.45 - <div template:id="memory-node" id="{template:this-element()}">
2.46 - <p template:element="memory-unit">Memory unit
2.47 - <select name="{template:list-attribute('value')}">
2.48 - <option template:element="memory-unit-enum" template:expr="@value-is-set" template:expr-attr="selected" template:value="@value"
2.49 - value="{@value}"></option>
2.50 - </select>
2.51 + <div template:id="memory-node" id="{template:this-element()}">
2.52 + <p template:element="memory-unit">Memory unit
2.53 + <select template:attribute="value" name="{template:this-attribute()}">
2.54 + <option template:element="memory-unit-enum" template:expr="@value-is-set" template:expr-attr="selected" template:value="@value"
2.55 + value="{@value}"></option>
2.56 + </select>
2.57
2.58 - <input type="submit" value="Remove"
2.59 - name="remove-memory-unit={template:this-element()}" /></p>
2.60 + <input type="submit" value="Remove"
2.61 + name="remove-memory-unit={template:this-element()}" />
2.62 + </p>
2.63
2.64 - <p>
2.65 - <input type="submit" value="Add memory"
2.66 - name="add-memory-unit={template:this-element()}" /></p>
2.67 + <p>
2.68 + <input type="submit" value="Add memory"
2.69 + name="add-memory-unit={template:this-element()}" />
2.70 + </p>
2.71 </div>
2.72 </div>
2.73 </div>
2.74 <div id="right">
2.75 - <div template:element="hard-disks" class="hard-disks">
2.76 - <h2>Hard Disks</h2>
2.77 + <div class="hard-disks" template:element="hard-disks">
2.78 + <h2>Hard Disks</h2>
2.79
2.80 - <div template:id="hard-disks-node" id="{template:this-element()}">
2.81 - <p template:element="hard-disk">Hard disk drive
2.82 - <select name="{template:list-attribute('value')}">
2.83 - <option template:element="hard-disk-enum" template:expr="@value-is-set" template:expr-attr="selected" template:value="@value"
2.84 - value="{@value}"></option>
2.85 - </select>
2.86 + <div template:id="hard-disks-node" id="{template:this-element()}">
2.87 + <p template:element="hard-disk">Hard disk drive
2.88 + <select template:attribute="value" name="{template:this-attribute()}">
2.89 + <option template:element="hard-disk-enum" template:expr="@value-is-set" template:expr-attr="selected" template:value="@value"
2.90 + value="{@value}"></option>
2.91 + </select>
2.92
2.93 - <input type="submit" value="Remove"
2.94 - name="remove-hard-disk={template:this-element()}" /></p>
2.95 + <input type="submit" value="Remove"
2.96 + name="remove-hard-disk={template:this-element()}" />
2.97 + </p>
2.98
2.99 - <p>
2.100 - <input type="submit" value="Add hard disk"
2.101 - name="add-hard-disk={template:this-element()}" /></p>
2.102 + <p>
2.103 + <input type="submit" value="Add hard disk"
2.104 + name="add-hard-disk={template:this-element()}" />
2.105 + </p>
2.106 </div>
2.107 </div>
2.108
2.109 <div template:element="storage" class="storage">
2.110 - <h2>Additional Storage</h2>
2.111 + <h2>Additional Storage</h2>
2.112
2.113 - <p template:element="storage-unit">Storage unit
2.114 - <select name="{template:list-attribute('value')}">
2.115 - <option template:element="storage-unit-enum" template:expr="@value-is-set" template:expr-attr="selected" template:value="@value"
2.116 - value="{@value}"></option>
2.117 - </select>
2.118 + <p template:element="storage-unit">Storage unit
2.119 + <select template:attribute="value" name="{template:this-attribute()}">
2.120 + <option template:element="storage-unit-enum" template:expr="@value-is-set" template:expr-attr="selected" template:value="@value"
2.121 + value="{@value}"></option>
2.122 + </select>
2.123
2.124 - <input type="submit" value="Remove"
2.125 - name="remove-storage-unit={template:this-element()}" /></p>
2.126 + <input type="submit" value="Remove"
2.127 + name="remove-storage-unit={template:this-element()}" />
2.128 + </p>
2.129
2.130 - <p>
2.131 - <input type="submit" value="Add storage"
2.132 - name="add-storage-unit={template:this-element()}" /></p>
2.133 + <p>
2.134 + <input type="submit" value="Add storage"
2.135 + name="add-storage-unit={template:this-element()}" /></p>
2.136 </div>
2.137 </div>
2.138 <div id="bottom">
2.139 <div template:element="peripherals" class="peripherals">
2.140 - <h2>Input Devices</h2>
2.141 + <h2>Input Devices</h2>
2.142
2.143 - <p template:element="keyboard">Keyboard
2.144 - <select name="{template:list-attribute('value')}">
2.145 - <option template:element="keyboard-enum" template:expr="@value-is-set" template:expr-attr="selected" template:value="@value"
2.146 - value="{@value}"></option>
2.147 - </select>
2.148 - </p>
2.149 + <p template:element="keyboard">Keyboard
2.150 + <select template:attribute="value" name="{template:this-attribute()}">
2.151 + <option template:element="keyboard-enum" template:expr="@value-is-set" template:expr-attr="selected" template:value="@value"
2.152 + value="{@value}"></option>
2.153 + </select>
2.154 + </p>
2.155
2.156 - <p template:element="mouse">Mouse
2.157 - <select name="{template:list-attribute('value')}">
2.158 - <option template:element="mouse-enum" template:expr="@value-is-set" template:expr-attr="selected" template:value="@value"
2.159 - value="{@value}"></option>
2.160 - </select>
2.161 - </p>
2.162 + <p template:element="mouse">Mouse
2.163 + <select template:attribute="value" name="{template:this-attribute()}">
2.164 + <option template:element="mouse-enum" template:expr="@value-is-set" template:expr-attr="selected" template:value="@value"
2.165 + value="{@value}"></option>
2.166 + </select>
2.167 + </p>
2.168
2.169 - <h2>Display</h2>
2.170 + <h2>Display</h2>
2.171
2.172 - <p template:element="screen">Screen
2.173 - <select name="{template:list-attribute('value')}">
2.174 - <option template:element="screen-enum" template:expr="@value-is-set" template:expr-attr="selected" template:value="@value"
2.175 - value="{@value}"></option>
2.176 - </select>
2.177 - </p>
2.178 + <p template:element="screen">Screen
2.179 + <select template:attribute="value" name="{template:this-attribute()}">
2.180 + <option template:element="screen-enum" template:expr="@value-is-set" template:expr-attr="selected" template:value="@value"
2.181 + value="{@value}"></option>
2.182 + </select>
2.183 + </p>
2.184 </div>
2.185
2.186 <div class="price">
2.187 - <h2>Price</h2>
2.188 + <h2>Price</h2>
2.189
2.190 - <p>Total for this configuration:
2.191 - <span template:value="sum(/configuration//*/@price)"></span></p>
2.192 + <p>Total for this configuration:
2.193 + <span template:value="sum(/configuration//*[@value-is-set]/@price)"></span></p>
2.194
2.195 - <p>
2.196 - <input type="submit" value="Update!" name="update" />
2.197 - <input type="submit" value="Export!" name="export" /></p>
2.198 + <p>
2.199 + <input type="submit" value="Update!" name="update" />
2.200 + <input type="submit" value="Export!" name="export" /></p>
2.201 </div>
2.202 </div>
2.203 </form>