1.1 --- a/examples/Common/Configurator/Resources/config_database.xml Fri May 06 19:13:50 2005 +0000
1.2 +++ b/examples/Common/Configurator/Resources/config_database.xml Sat May 07 00:45:09 2005 +0000
1.3 @@ -2,13 +2,15 @@
1.4 <database>
1.5 <base-system>
1.6 <base-system-enum value="(Not selected)" price="0"/>
1.7 - <base-system-enum value="Shuttle SB61G2V3" price="2174"/>
1.8 - <base-system-enum value="Shuttle SB65G2" price="2700"/>
1.9 + <base-system-enum value="Shuttle SB61G2V3" price="2174" cpu-socket="478"/>
1.10 + <base-system-enum value="Shuttle SB65G2" price="2700" cpu-socket="478"/>
1.11 + <base-system-enum value="Soltek Qbic EQ3901" price="2500" cpu-socket="939"/>
1.12 </base-system>
1.13 <cpu>
1.14 <cpu-enum value="(Not selected)" price="0"/>
1.15 - <cpu-enum value="Pentium 4 3.0 GHz" price="1650"/>
1.16 - <cpu-enum value="Athlon 3000+" price="1500"/>
1.17 + <cpu-enum value="Pentium 4 3.0 GHz" price="1650" cpu-socket="478"/>
1.18 + <cpu-enum value="Athlon 3000+" price="1500" cpu-socket="A"/>
1.19 + <cpu-enum value="Athlon 64 3500+" price="2300" cpu-socket="939"/>
1.20 </cpu>
1.21 <memory-unit>
1.22 <memory-unit-enum value="(Not selected)" price="0"/>
2.1 --- a/examples/Common/Configurator/Resources/config_database.xsl Fri May 06 19:13:50 2005 +0000
2.2 +++ b/examples/Common/Configurator/Resources/config_database.xsl Sat May 07 00:45:09 2005 +0000
2.3 @@ -1,6 +1,8 @@
2.4 <?xml version="1.0" encoding="utf-8"?>
2.5 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
2.6 xmlns:template="http://www.boddie.org.uk/ns/xmltools/template"
2.7 + xmlns:dyn="http://exslt.org/dynamic"
2.8 + extension-element-prefixes="dyn"
2.9 version="1.0">
2.10
2.11 <xsl:param name="database"/>
2.12 @@ -11,18 +13,21 @@
2.13 <!-- Complete all multiple choice fields. -->
2.14 <details>
2.15 <xsl:call-template name="complete-element">
2.16 - <xsl:with-param name="found-elements" select="details/base-system"/>
2.17 + <xsl:with-param name="found-element" select="details/base-system[1]"/>
2.18 <xsl:with-param name="element-name">base-system</xsl:with-param>
2.19 </xsl:call-template>
2.20 <xsl:call-template name="complete-element">
2.21 - <xsl:with-param name="found-elements" select="details/cpu"/>
2.22 + <xsl:with-param name="found-element" select="details/cpu[1]"/>
2.23 + <xsl:with-param name="control-element" select="details/base-system[1]"/>
2.24 <xsl:with-param name="element-name">cpu</xsl:with-param>
2.25 + <xsl:with-param name="control-element-name">base-system</xsl:with-param>
2.26 + <xsl:with-param name="control-attribute-name">cpu-socket</xsl:with-param>
2.27 </xsl:call-template>
2.28 </details>
2.29 <memory>
2.30 <xsl:for-each select="memory/memory-unit">
2.31 <xsl:call-template name="complete-element">
2.32 - <xsl:with-param name="found-elements" select="."/>
2.33 + <xsl:with-param name="found-element" select="."/>
2.34 <xsl:with-param name="element-name">memory-unit</xsl:with-param>
2.35 </xsl:call-template>
2.36 </xsl:for-each>
2.37 @@ -30,7 +35,7 @@
2.38 <hard-disks>
2.39 <xsl:for-each select="hard-disks/hard-disk">
2.40 <xsl:call-template name="complete-element">
2.41 - <xsl:with-param name="found-elements" select="."/>
2.42 + <xsl:with-param name="found-element" select="."/>
2.43 <xsl:with-param name="element-name">hard-disk</xsl:with-param>
2.44 </xsl:call-template>
2.45 </xsl:for-each>
2.46 @@ -38,22 +43,22 @@
2.47 <storage>
2.48 <xsl:for-each select="storage/storage-unit">
2.49 <xsl:call-template name="complete-element">
2.50 - <xsl:with-param name="found-elements" select="."/>
2.51 + <xsl:with-param name="found-element" select="."/>
2.52 <xsl:with-param name="element-name">storage-unit</xsl:with-param>
2.53 </xsl:call-template>
2.54 </xsl:for-each>
2.55 </storage>
2.56 <peripherals>
2.57 <xsl:call-template name="complete-element">
2.58 - <xsl:with-param name="found-elements" select="peripherals/keyboard"/>
2.59 + <xsl:with-param name="found-element" select="peripherals/keyboard[1]"/>
2.60 <xsl:with-param name="element-name">keyboard</xsl:with-param>
2.61 </xsl:call-template>
2.62 <xsl:call-template name="complete-element">
2.63 - <xsl:with-param name="found-elements" select="peripherals/mouse"/>
2.64 + <xsl:with-param name="found-element" select="peripherals/mouse[1]"/>
2.65 <xsl:with-param name="element-name">mouse</xsl:with-param>
2.66 </xsl:call-template>
2.67 <xsl:call-template name="complete-element">
2.68 - <xsl:with-param name="found-elements" select="peripherals/screen"/>
2.69 + <xsl:with-param name="found-element" select="peripherals/screen[1]"/>
2.70 <xsl:with-param name="element-name">screen</xsl:with-param>
2.71 </xsl:call-template>
2.72 </peripherals>
2.73 @@ -61,34 +66,60 @@
2.74 </xsl:template>
2.75
2.76 <xsl:template name="complete-element">
2.77 - <xsl:param name="found-elements"/>
2.78 + <!-- Input parameters. -->
2.79 + <xsl:param name="found-element"/>
2.80 + <xsl:param name="control-element"/>
2.81 + <!-- Database parameters. -->
2.82 <xsl:param name="element-name"/>
2.83 + <xsl:param name="control-element-name"/>
2.84 + <xsl:param name="control-attribute-name"/>
2.85 + <!-- Find the database entries. -->
2.86 <xsl:variable name="element-enum-name"><xsl:value-of select="$element-name"/>-enum</xsl:variable>
2.87 - <xsl:variable name="has-set-values" select="$found-elements[@value]"/>
2.88 + <xsl:variable name="control-element-enum-name"><xsl:value-of select="$control-element-name"/>-enum</xsl:variable>
2.89 + <!-- Find whether the input values are set. -->
2.90 + <xsl:variable name="has-set-values" select="$found-element[@value]"/>
2.91 + <xsl:variable name="has-control-values" select="$control-element and $control-element[@value]"/>
2.92 + <!-- Get the database element for the element being prepared. -->
2.93 + <xsl:variable name="database-element" select="$database/database/*[local-name() = $element-name]"/>
2.94 + <!-- Get the database element for the control element. -->
2.95 + <xsl:variable name="database-control-element" select="$database/database/*[local-name() = $control-element-name]"/>
2.96 + <!-- Get the database entries for the control element. -->
2.97 + <xsl:variable name="control-enum-elements" select="$database-control-element/*[local-name() = $control-element-enum-name]"/>
2.98 + <!-- Get the database entry for the control element, then get the control attribute value in that entry. -->
2.99 + <xsl:variable name="other-control-value" select="$control-enum-elements[@value = $control-element/@value]/@*[local-name() = $control-attribute-name]"/>
2.100 <!-- Make the element with the different values. -->
2.101 <xsl:element name="{$element-name}">
2.102 - <!-- Find the values in the database. -->
2.103 - <xsl:for-each select="$database/database/*[local-name() = $element-name]/*[local-name() = $element-enum-name]">
2.104 + <!-- Find the entries in the database for the element being prepared. -->
2.105 + <xsl:for-each select="$database-element/*[local-name() = $element-enum-name]">
2.106 + <!-- Remember the current node for future comparisons. -->
2.107 <xsl:variable name="enum-element" select="."/>
2.108 - <!-- Copy each option. -->
2.109 - <xsl:copy>
2.110 - <!-- Only include the value, adding the price only if the item is selected. -->
2.111 - <xsl:apply-templates select="@value"/>
2.112 - <!-- Find whether this item is selected. -->
2.113 - <xsl:choose>
2.114 - <!-- In the current field, the value attribute matches this value. -->
2.115 - <xsl:when test="$found-elements[@value = $enum-element/@value]">
2.116 - <xsl:attribute name="value-is-set">true</xsl:attribute>
2.117 - <xsl:apply-templates select="@price"/>
2.118 - </xsl:when>
2.119 - <!-- This value is the first and no value attribute is specified. -->
2.120 - <xsl:when test="not($has-set-values) and count($enum-element/preceding-sibling::*) = 0">
2.121 - <xsl:attribute name="value-is-set">true</xsl:attribute>
2.122 - <xsl:apply-templates select="@price"/>
2.123 - </xsl:when>
2.124 - <xsl:otherwise/>
2.125 - </xsl:choose>
2.126 - </xsl:copy>
2.127 + <!-- Find whether the current entry matches the input value. -->
2.128 + <xsl:variable name="matching-element" select="$found-element[@value = $enum-element/@value]"/>
2.129 + <!-- Get the control attribute value for the current entry. -->
2.130 + <xsl:variable name="this-control-value" select="@*[local-name() = $control-attribute-name]"/>
2.131 + <!-- Filter the entry out unless no control element was given, this entry has no control attribute value or...
2.132 + if the control attribute value matches the one for the control element. -->
2.133 + <xsl:if test="not($has-control-values) or not($this-control-value) or $this-control-value = $other-control-value">
2.134 + <!-- Copy the entry. -->
2.135 + <xsl:copy>
2.136 + <!-- Include all attributes except the price, adding the price only if the item is selected. -->
2.137 + <xsl:apply-templates select="@*[local-name() != 'price']"/>
2.138 + <!-- Find whether this item is selected. -->
2.139 + <xsl:choose>
2.140 + <!-- In the current field, the value attribute matches this value. -->
2.141 + <xsl:when test="$matching-element">
2.142 + <xsl:attribute name="value-is-set">true</xsl:attribute>
2.143 + <xsl:apply-templates select="@price"/>
2.144 + </xsl:when>
2.145 + <!-- This value is the first and no value attribute is specified. -->
2.146 + <xsl:when test="not($has-set-values) and count($enum-element/preceding-sibling::*) = 0">
2.147 + <xsl:attribute name="value-is-set">true</xsl:attribute>
2.148 + <xsl:apply-templates select="@price"/>
2.149 + </xsl:when>
2.150 + <xsl:otherwise/>
2.151 + </xsl:choose>
2.152 + </xsl:copy>
2.153 + </xsl:if>
2.154 </xsl:for-each>
2.155 </xsl:element>
2.156 </xsl:template>