paulb@30 | 1 | <?xml version="1.0" encoding="utf-8"?> |
paulb@30 | 2 | <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
paulb@30 | 3 | xmlns:template="http://www.boddie.org.uk/ns/xmltools/template" |
paulb@30 | 4 | version="1.0"> |
paulb@30 | 5 | |
paulb@30 | 6 | <xsl:param name="database"/> |
paulb@30 | 7 | |
paulb@30 | 8 | <xsl:template match="configuration"> |
paulb@30 | 9 | <xsl:copy> |
paulb@30 | 10 | <xsl:apply-templates select="@*"/> |
paulb@30 | 11 | <!-- Complete all multiple choice fields. --> |
paulb@30 | 12 | <details> |
paulb@30 | 13 | <xsl:call-template name="complete-element"> |
paulb@30 | 14 | <xsl:with-param name="found-elements" select="details/base-system"/> |
paulb@30 | 15 | <xsl:with-param name="element-name">base-system</xsl:with-param> |
paulb@30 | 16 | </xsl:call-template> |
paulb@30 | 17 | <xsl:call-template name="complete-element"> |
paulb@30 | 18 | <xsl:with-param name="found-elements" select="details/cpu"/> |
paulb@30 | 19 | <xsl:with-param name="element-name">cpu</xsl:with-param> |
paulb@30 | 20 | </xsl:call-template> |
paulb@30 | 21 | </details> |
paulb@30 | 22 | <memory> |
paulb@30 | 23 | <xsl:for-each select="memory/memory-unit"> |
paulb@30 | 24 | <xsl:call-template name="complete-element"> |
paulb@30 | 25 | <xsl:with-param name="found-elements" select="."/> |
paulb@30 | 26 | <xsl:with-param name="element-name">memory-unit</xsl:with-param> |
paulb@30 | 27 | </xsl:call-template> |
paulb@30 | 28 | </xsl:for-each> |
paulb@30 | 29 | </memory> |
paulb@30 | 30 | <hard-disks> |
paulb@30 | 31 | <xsl:for-each select="hard-disks/hard-disk"> |
paulb@30 | 32 | <xsl:call-template name="complete-element"> |
paulb@30 | 33 | <xsl:with-param name="found-elements" select="."/> |
paulb@30 | 34 | <xsl:with-param name="element-name">hard-disk</xsl:with-param> |
paulb@30 | 35 | </xsl:call-template> |
paulb@30 | 36 | </xsl:for-each> |
paulb@30 | 37 | </hard-disks> |
paulb@30 | 38 | <storage> |
paulb@30 | 39 | <xsl:for-each select="storage/storage-unit"> |
paulb@30 | 40 | <xsl:call-template name="complete-element"> |
paulb@30 | 41 | <xsl:with-param name="found-elements" select="."/> |
paulb@30 | 42 | <xsl:with-param name="element-name">storage-unit</xsl:with-param> |
paulb@30 | 43 | </xsl:call-template> |
paulb@30 | 44 | </xsl:for-each> |
paulb@30 | 45 | </storage> |
paulb@30 | 46 | <peripherals> |
paulb@30 | 47 | <xsl:call-template name="complete-element"> |
paulb@30 | 48 | <xsl:with-param name="found-elements" select="peripherals/keyboard"/> |
paulb@30 | 49 | <xsl:with-param name="element-name">keyboard</xsl:with-param> |
paulb@30 | 50 | </xsl:call-template> |
paulb@30 | 51 | <xsl:call-template name="complete-element"> |
paulb@30 | 52 | <xsl:with-param name="found-elements" select="peripherals/mouse"/> |
paulb@30 | 53 | <xsl:with-param name="element-name">mouse</xsl:with-param> |
paulb@30 | 54 | </xsl:call-template> |
paulb@30 | 55 | <xsl:call-template name="complete-element"> |
paulb@30 | 56 | <xsl:with-param name="found-elements" select="peripherals/screen"/> |
paulb@30 | 57 | <xsl:with-param name="element-name">screen</xsl:with-param> |
paulb@30 | 58 | </xsl:call-template> |
paulb@30 | 59 | </peripherals> |
paulb@30 | 60 | </xsl:copy> |
paulb@30 | 61 | </xsl:template> |
paulb@30 | 62 | |
paulb@30 | 63 | <xsl:template name="complete-element"> |
paulb@30 | 64 | <xsl:param name="found-elements"/> |
paulb@30 | 65 | <xsl:param name="element-name"/> |
paulb@30 | 66 | <xsl:variable name="element-enum-name"><xsl:value-of select="$element-name"/>-enum</xsl:variable> |
paulb@30 | 67 | <xsl:variable name="has-set-values" select="$found-elements[@value]"/> |
paulb@30 | 68 | <!-- Make the element with the different values. --> |
paulb@30 | 69 | <xsl:element name="{$element-name}"> |
paulb@30 | 70 | <!-- Find the values in the database. --> |
paulb@30 | 71 | <xsl:for-each select="$database/database/*[local-name() = $element-name]/*[local-name() = $element-enum-name]"> |
paulb@30 | 72 | <xsl:variable name="enum-element" select="."/> |
paulb@30 | 73 | <!-- Copy each option. --> |
paulb@30 | 74 | <xsl:copy> |
paulb@30 | 75 | <!-- Only include the value, adding the price only if the item is selected. --> |
paulb@30 | 76 | <xsl:apply-templates select="@value"/> |
paulb@30 | 77 | <!-- Find whether this item is selected. --> |
paulb@30 | 78 | <xsl:choose> |
paulb@30 | 79 | <!-- In the current field, the value attribute matches this value. --> |
paulb@30 | 80 | <xsl:when test="$found-elements[@value = $enum-element/@value]"> |
paulb@30 | 81 | <xsl:attribute name="value-is-set">true</xsl:attribute> |
paulb@30 | 82 | <xsl:apply-templates select="@price"/> |
paulb@30 | 83 | </xsl:when> |
paulb@30 | 84 | <!-- This value is the first and no value attribute is specified. --> |
paulb@30 | 85 | <xsl:when test="not($has-set-values) and count($enum-element/preceding-sibling::*) = 0"> |
paulb@30 | 86 | <xsl:attribute name="value-is-set">true</xsl:attribute> |
paulb@30 | 87 | <xsl:apply-templates select="@price"/> |
paulb@30 | 88 | </xsl:when> |
paulb@30 | 89 | <xsl:otherwise/> |
paulb@30 | 90 | </xsl:choose> |
paulb@30 | 91 | </xsl:copy> |
paulb@30 | 92 | </xsl:for-each> |
paulb@30 | 93 | </xsl:element> |
paulb@30 | 94 | </xsl:template> |
paulb@30 | 95 | |
paulb@30 | 96 | <!-- Replicate unknown elements. --> |
paulb@30 | 97 | |
paulb@30 | 98 | <xsl:template match="@*|node()"> |
paulb@30 | 99 | <xsl:copy> |
paulb@30 | 100 | <xsl:apply-templates select="@*|node()"/> |
paulb@30 | 101 | </xsl:copy> |
paulb@30 | 102 | </xsl:template> |
paulb@30 | 103 | |
paulb@30 | 104 | </xsl:stylesheet> |