1.1 --- a/examples/Common/Configurator/Resources/config_database.xsl Fri May 06 19:13:50 2005 +0000
1.2 +++ b/examples/Common/Configurator/Resources/config_database.xsl Sat May 07 00:45:09 2005 +0000
1.3 @@ -1,6 +1,8 @@
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 @@ -11,18 +13,21 @@
1.13 <!-- Complete all multiple choice fields. -->
1.14 <details>
1.15 <xsl:call-template name="complete-element">
1.16 - <xsl:with-param name="found-elements" select="details/base-system"/>
1.17 + <xsl:with-param name="found-element" select="details/base-system[1]"/>
1.18 <xsl:with-param name="element-name">base-system</xsl:with-param>
1.19 </xsl:call-template>
1.20 <xsl:call-template name="complete-element">
1.21 - <xsl:with-param name="found-elements" select="details/cpu"/>
1.22 + <xsl:with-param name="found-element" select="details/cpu[1]"/>
1.23 + <xsl:with-param name="control-element" select="details/base-system[1]"/>
1.24 <xsl:with-param name="element-name">cpu</xsl:with-param>
1.25 + <xsl:with-param name="control-element-name">base-system</xsl:with-param>
1.26 + <xsl:with-param name="control-attribute-name">cpu-socket</xsl:with-param>
1.27 </xsl:call-template>
1.28 </details>
1.29 <memory>
1.30 <xsl:for-each select="memory/memory-unit">
1.31 <xsl:call-template name="complete-element">
1.32 - <xsl:with-param name="found-elements" select="."/>
1.33 + <xsl:with-param name="found-element" select="."/>
1.34 <xsl:with-param name="element-name">memory-unit</xsl:with-param>
1.35 </xsl:call-template>
1.36 </xsl:for-each>
1.37 @@ -30,7 +35,7 @@
1.38 <hard-disks>
1.39 <xsl:for-each select="hard-disks/hard-disk">
1.40 <xsl:call-template name="complete-element">
1.41 - <xsl:with-param name="found-elements" select="."/>
1.42 + <xsl:with-param name="found-element" select="."/>
1.43 <xsl:with-param name="element-name">hard-disk</xsl:with-param>
1.44 </xsl:call-template>
1.45 </xsl:for-each>
1.46 @@ -38,22 +43,22 @@
1.47 <storage>
1.48 <xsl:for-each select="storage/storage-unit">
1.49 <xsl:call-template name="complete-element">
1.50 - <xsl:with-param name="found-elements" select="."/>
1.51 + <xsl:with-param name="found-element" select="."/>
1.52 <xsl:with-param name="element-name">storage-unit</xsl:with-param>
1.53 </xsl:call-template>
1.54 </xsl:for-each>
1.55 </storage>
1.56 <peripherals>
1.57 <xsl:call-template name="complete-element">
1.58 - <xsl:with-param name="found-elements" select="peripherals/keyboard"/>
1.59 + <xsl:with-param name="found-element" select="peripherals/keyboard[1]"/>
1.60 <xsl:with-param name="element-name">keyboard</xsl:with-param>
1.61 </xsl:call-template>
1.62 <xsl:call-template name="complete-element">
1.63 - <xsl:with-param name="found-elements" select="peripherals/mouse"/>
1.64 + <xsl:with-param name="found-element" select="peripherals/mouse[1]"/>
1.65 <xsl:with-param name="element-name">mouse</xsl:with-param>
1.66 </xsl:call-template>
1.67 <xsl:call-template name="complete-element">
1.68 - <xsl:with-param name="found-elements" select="peripherals/screen"/>
1.69 + <xsl:with-param name="found-element" select="peripherals/screen[1]"/>
1.70 <xsl:with-param name="element-name">screen</xsl:with-param>
1.71 </xsl:call-template>
1.72 </peripherals>
1.73 @@ -61,34 +66,60 @@
1.74 </xsl:template>
1.75
1.76 <xsl:template name="complete-element">
1.77 - <xsl:param name="found-elements"/>
1.78 + <!-- Input parameters. -->
1.79 + <xsl:param name="found-element"/>
1.80 + <xsl:param name="control-element"/>
1.81 + <!-- Database parameters. -->
1.82 <xsl:param name="element-name"/>
1.83 + <xsl:param name="control-element-name"/>
1.84 + <xsl:param name="control-attribute-name"/>
1.85 + <!-- Find the database entries. -->
1.86 <xsl:variable name="element-enum-name"><xsl:value-of select="$element-name"/>-enum</xsl:variable>
1.87 - <xsl:variable name="has-set-values" select="$found-elements[@value]"/>
1.88 + <xsl:variable name="control-element-enum-name"><xsl:value-of select="$control-element-name"/>-enum</xsl:variable>
1.89 + <!-- Find whether the input values are set. -->
1.90 + <xsl:variable name="has-set-values" select="$found-element[@value]"/>
1.91 + <xsl:variable name="has-control-values" select="$control-element and $control-element[@value]"/>
1.92 + <!-- Get the database element for the element being prepared. -->
1.93 + <xsl:variable name="database-element" select="$database/database/*[local-name() = $element-name]"/>
1.94 + <!-- Get the database element for the control element. -->
1.95 + <xsl:variable name="database-control-element" select="$database/database/*[local-name() = $control-element-name]"/>
1.96 + <!-- Get the database entries for the control element. -->
1.97 + <xsl:variable name="control-enum-elements" select="$database-control-element/*[local-name() = $control-element-enum-name]"/>
1.98 + <!-- Get the database entry for the control element, then get the control attribute value in that entry. -->
1.99 + <xsl:variable name="other-control-value" select="$control-enum-elements[@value = $control-element/@value]/@*[local-name() = $control-attribute-name]"/>
1.100 <!-- Make the element with the different values. -->
1.101 <xsl:element name="{$element-name}">
1.102 - <!-- Find the values in the database. -->
1.103 - <xsl:for-each select="$database/database/*[local-name() = $element-name]/*[local-name() = $element-enum-name]">
1.104 + <!-- Find the entries in the database for the element being prepared. -->
1.105 + <xsl:for-each select="$database-element/*[local-name() = $element-enum-name]">
1.106 + <!-- Remember the current node for future comparisons. -->
1.107 <xsl:variable name="enum-element" select="."/>
1.108 - <!-- Copy each option. -->
1.109 - <xsl:copy>
1.110 - <!-- Only include the value, adding the price only if the item is selected. -->
1.111 - <xsl:apply-templates select="@value"/>
1.112 - <!-- Find whether this item is selected. -->
1.113 - <xsl:choose>
1.114 - <!-- In the current field, the value attribute matches this value. -->
1.115 - <xsl:when test="$found-elements[@value = $enum-element/@value]">
1.116 - <xsl:attribute name="value-is-set">true</xsl:attribute>
1.117 - <xsl:apply-templates select="@price"/>
1.118 - </xsl:when>
1.119 - <!-- This value is the first and no value attribute is specified. -->
1.120 - <xsl:when test="not($has-set-values) and count($enum-element/preceding-sibling::*) = 0">
1.121 - <xsl:attribute name="value-is-set">true</xsl:attribute>
1.122 - <xsl:apply-templates select="@price"/>
1.123 - </xsl:when>
1.124 - <xsl:otherwise/>
1.125 - </xsl:choose>
1.126 - </xsl:copy>
1.127 + <!-- Find whether the current entry matches the input value. -->
1.128 + <xsl:variable name="matching-element" select="$found-element[@value = $enum-element/@value]"/>
1.129 + <!-- Get the control attribute value for the current entry. -->
1.130 + <xsl:variable name="this-control-value" select="@*[local-name() = $control-attribute-name]"/>
1.131 + <!-- Filter the entry out unless no control element was given, this entry has no control attribute value or...
1.132 + if the control attribute value matches the one for the control element. -->
1.133 + <xsl:if test="not($has-control-values) or not($this-control-value) or $this-control-value = $other-control-value">
1.134 + <!-- Copy the entry. -->
1.135 + <xsl:copy>
1.136 + <!-- Include all attributes except the price, adding the price only if the item is selected. -->
1.137 + <xsl:apply-templates select="@*[local-name() != 'price']"/>
1.138 + <!-- Find whether this item is selected. -->
1.139 + <xsl:choose>
1.140 + <!-- In the current field, the value attribute matches this value. -->
1.141 + <xsl:when test="$matching-element">
1.142 + <xsl:attribute name="value-is-set">true</xsl:attribute>
1.143 + <xsl:apply-templates select="@price"/>
1.144 + </xsl:when>
1.145 + <!-- This value is the first and no value attribute is specified. -->
1.146 + <xsl:when test="not($has-set-values) and count($enum-element/preceding-sibling::*) = 0">
1.147 + <xsl:attribute name="value-is-set">true</xsl:attribute>
1.148 + <xsl:apply-templates select="@price"/>
1.149 + </xsl:when>
1.150 + <xsl:otherwise/>
1.151 + </xsl:choose>
1.152 + </xsl:copy>
1.153 + </xsl:if>
1.154 </xsl:for-each>
1.155 </xsl:element>
1.156 </xsl:template>