1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/examples/Common/Configurator/Resources/config_database.xsl Thu Dec 30 02:03:35 2004 +0000
1.3 @@ -0,0 +1,104 @@
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 + version="1.0">
1.8 +
1.9 + <xsl:param name="database"/>
1.10 +
1.11 + <xsl:template match="configuration">
1.12 + <xsl:copy>
1.13 + <xsl:apply-templates select="@*"/>
1.14 + <!-- Complete all multiple choice fields. -->
1.15 + <details>
1.16 + <xsl:call-template name="complete-element">
1.17 + <xsl:with-param name="found-elements" select="details/base-system"/>
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="element-name">cpu</xsl:with-param>
1.23 + </xsl:call-template>
1.24 + </details>
1.25 + <memory>
1.26 + <xsl:for-each select="memory/memory-unit">
1.27 + <xsl:call-template name="complete-element">
1.28 + <xsl:with-param name="found-elements" select="."/>
1.29 + <xsl:with-param name="element-name">memory-unit</xsl:with-param>
1.30 + </xsl:call-template>
1.31 + </xsl:for-each>
1.32 + </memory>
1.33 + <hard-disks>
1.34 + <xsl:for-each select="hard-disks/hard-disk">
1.35 + <xsl:call-template name="complete-element">
1.36 + <xsl:with-param name="found-elements" select="."/>
1.37 + <xsl:with-param name="element-name">hard-disk</xsl:with-param>
1.38 + </xsl:call-template>
1.39 + </xsl:for-each>
1.40 + </hard-disks>
1.41 + <storage>
1.42 + <xsl:for-each select="storage/storage-unit">
1.43 + <xsl:call-template name="complete-element">
1.44 + <xsl:with-param name="found-elements" select="."/>
1.45 + <xsl:with-param name="element-name">storage-unit</xsl:with-param>
1.46 + </xsl:call-template>
1.47 + </xsl:for-each>
1.48 + </storage>
1.49 + <peripherals>
1.50 + <xsl:call-template name="complete-element">
1.51 + <xsl:with-param name="found-elements" select="peripherals/keyboard"/>
1.52 + <xsl:with-param name="element-name">keyboard</xsl:with-param>
1.53 + </xsl:call-template>
1.54 + <xsl:call-template name="complete-element">
1.55 + <xsl:with-param name="found-elements" select="peripherals/mouse"/>
1.56 + <xsl:with-param name="element-name">mouse</xsl:with-param>
1.57 + </xsl:call-template>
1.58 + <xsl:call-template name="complete-element">
1.59 + <xsl:with-param name="found-elements" select="peripherals/screen"/>
1.60 + <xsl:with-param name="element-name">screen</xsl:with-param>
1.61 + </xsl:call-template>
1.62 + </peripherals>
1.63 + </xsl:copy>
1.64 + </xsl:template>
1.65 +
1.66 + <xsl:template name="complete-element">
1.67 + <xsl:param name="found-elements"/>
1.68 + <xsl:param name="element-name"/>
1.69 + <xsl:variable name="element-enum-name"><xsl:value-of select="$element-name"/>-enum</xsl:variable>
1.70 + <xsl:variable name="has-set-values" select="$found-elements[@value]"/>
1.71 + <!-- Make the element with the different values. -->
1.72 + <xsl:element name="{$element-name}">
1.73 + <!-- Find the values in the database. -->
1.74 + <xsl:for-each select="$database/database/*[local-name() = $element-name]/*[local-name() = $element-enum-name]">
1.75 + <xsl:variable name="enum-element" select="."/>
1.76 + <!-- Copy each option. -->
1.77 + <xsl:copy>
1.78 + <!-- Only include the value, adding the price only if the item is selected. -->
1.79 + <xsl:apply-templates select="@value"/>
1.80 + <!-- Find whether this item is selected. -->
1.81 + <xsl:choose>
1.82 + <!-- In the current field, the value attribute matches this value. -->
1.83 + <xsl:when test="$found-elements[@value = $enum-element/@value]">
1.84 + <xsl:attribute name="value-is-set">true</xsl:attribute>
1.85 + <xsl:apply-templates select="@price"/>
1.86 + </xsl:when>
1.87 + <!-- This value is the first and no value attribute is specified. -->
1.88 + <xsl:when test="not($has-set-values) and count($enum-element/preceding-sibling::*) = 0">
1.89 + <xsl:attribute name="value-is-set">true</xsl:attribute>
1.90 + <xsl:apply-templates select="@price"/>
1.91 + </xsl:when>
1.92 + <xsl:otherwise/>
1.93 + </xsl:choose>
1.94 + </xsl:copy>
1.95 + </xsl:for-each>
1.96 + </xsl:element>
1.97 + </xsl:template>
1.98 +
1.99 + <!-- Replicate unknown elements. -->
1.100 +
1.101 + <xsl:template match="@*|node()">
1.102 + <xsl:copy>
1.103 + <xsl:apply-templates select="@*|node()"/>
1.104 + </xsl:copy>
1.105 + </xsl:template>
1.106 +
1.107 +</xsl:stylesheet>