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()">