XSLTools

examples/Common/Configurator/Resources/config_database.xsl

265:59fdbcae2113
2005-10-03 paulb [project @ 2005-10-03 19:11:12 by paulb] Switched to using input/initialiser stylesheets, restricting additional transformations to those filtering the choices in the output.
     1 <?xml version="1.0" encoding="utf-8"?>     2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"     3                 version="1.0">     4      5   <xsl:param name="database"/>     6      7   <xsl:template match="configuration">     8     <xsl:copy>     9       <xsl:apply-templates select="@*"/>    10       <!-- Find out some additional information. -->    11       <xsl:variable name="cpu-socket" select="$database/database/base-system/base-system-enum[@value = current()/details/base-system/@value]/@cpu-socket"/>    12       <xsl:variable name="interface" select="$database/database/base-system/base-system-enum[@value = current()/details/base-system/@value]/@interface"/>    13       <!-- Complete all multiple choice fields. -->    14       <details>    15         <base-system>    16           <xsl:variable name="value" select="details/base-system/@value"/>    17           <xsl:attribute name="value"><xsl:value-of select="$value"/></xsl:attribute>    18           <xsl:for-each select="$database/database/base-system/base-system-enum">    19             <xsl:copy>    20               <xsl:apply-templates select="@*"/>    21               <xsl:if test="@value = $value">    22                 <xsl:attribute name="value-is-set">true</xsl:attribute>    23               </xsl:if>    24             </xsl:copy>    25           </xsl:for-each>    26         </base-system>    27         <cpu>    28           <xsl:variable name="value" select="details/cpu/@value"/>    29           <xsl:attribute name="value"><xsl:value-of select="$value"/></xsl:attribute>    30           <xsl:for-each select="$database/database/cpu/cpu-enum[@cpu-socket = $cpu-socket or not(@cpu-socket)]">    31             <xsl:copy>    32               <xsl:apply-templates select="@*"/>    33               <xsl:if test="@value = $value">    34                 <xsl:attribute name="value-is-set">true</xsl:attribute>    35               </xsl:if>    36             </xsl:copy>    37           </xsl:for-each>    38         </cpu>    39       </details>    40       <memory>    41         <xsl:for-each select="memory/memory-unit">    42           <xsl:copy>    43             <xsl:variable name="value" select="@value"/>    44             <xsl:attribute name="value"><xsl:value-of select="$value"/></xsl:attribute>    45             <xsl:for-each select="$database/database/memory-unit/memory-unit-enum">    46               <xsl:copy>    47                 <xsl:apply-templates select="@*"/>    48                 <xsl:if test="@value = $value">    49                   <xsl:attribute name="value-is-set">true</xsl:attribute>    50                 </xsl:if>    51               </xsl:copy>    52             </xsl:for-each>    53           </xsl:copy>    54         </xsl:for-each>    55       </memory>    56       <hard-disks>    57         <xsl:for-each select="hard-disks/hard-disk">    58           <xsl:copy>    59             <xsl:variable name="value" select="@value"/>    60             <xsl:attribute name="value"><xsl:value-of select="$value"/></xsl:attribute>    61             <xsl:for-each select="$database/database/hard-disk/hard-disk-enum[@interface = $interface or not(@interface)]">    62               <xsl:copy>    63                 <xsl:apply-templates select="@*"/>    64                 <xsl:if test="@value = $value">    65                   <xsl:attribute name="value-is-set">true</xsl:attribute>    66                 </xsl:if>    67               </xsl:copy>    68             </xsl:for-each>    69           </xsl:copy>    70         </xsl:for-each>    71       </hard-disks>    72       <storage>    73         <xsl:for-each select="storage/storage-unit">    74           <xsl:copy>    75             <xsl:variable name="value" select="@value"/>    76             <xsl:attribute name="value"><xsl:value-of select="$value"/></xsl:attribute>    77             <xsl:for-each select="$database/database/storage-unit/storage-unit-enum">    78               <xsl:copy>    79                 <xsl:apply-templates select="@*"/>    80                 <xsl:if test="@value = $value">    81                   <xsl:attribute name="value-is-set">true</xsl:attribute>    82                 </xsl:if>    83               </xsl:copy>    84             </xsl:for-each>    85           </xsl:copy>    86         </xsl:for-each>    87       </storage>    88       <accessories>    89         <xsl:variable name="values" select="accessories/accessory-enum/@value"/>    90         <xsl:variable name="storage-values" select="storage/storage-unit/@value"/>    91         <xsl:for-each select="$database/database/accessories/accessory-enum">    92           <xsl:if test="$storage-values[string() = current()/@storage] or not(@storage)">    93             <xsl:copy>    94               <xsl:apply-templates select="@*"/>    95               <xsl:if test="$values[string() = current()/@value]">    96                 <xsl:attribute name="value-is-set">true</xsl:attribute>    97               </xsl:if>    98             </xsl:copy>    99           </xsl:if>   100         </xsl:for-each>   101       </accessories>   102       <peripherals>   103         <keyboard>   104           <xsl:variable name="value" select="peripherals/keyboard/@value"/>   105           <xsl:attribute name="value"><xsl:value-of select="$value"/></xsl:attribute>   106           <xsl:for-each select="$database/database/keyboard/keyboard-enum">   107             <xsl:copy>   108               <xsl:apply-templates select="@*"/>   109               <xsl:if test="@value = $value">   110                 <xsl:attribute name="value-is-set">true</xsl:attribute>   111               </xsl:if>   112             </xsl:copy>   113           </xsl:for-each>   114         </keyboard>   115         <mouse>   116           <xsl:variable name="value" select="peripherals/mouse/@value"/>   117           <xsl:attribute name="value"><xsl:value-of select="$value"/></xsl:attribute>   118           <xsl:for-each select="$database/database/mouse/mouse-enum">   119             <xsl:copy>   120               <xsl:apply-templates select="@*"/>   121               <xsl:if test="@value = $value">   122                 <xsl:attribute name="value-is-set">true</xsl:attribute>   123               </xsl:if>   124             </xsl:copy>   125           </xsl:for-each>   126         </mouse>   127         <screen>   128           <xsl:variable name="value" select="peripherals/screen/@value"/>   129           <xsl:attribute name="value"><xsl:value-of select="$value"/></xsl:attribute>   130           <xsl:for-each select="$database/database/screen/screen-enum">   131             <xsl:copy>   132               <xsl:apply-templates select="@*"/>   133               <xsl:if test="@value = $value">   134                 <xsl:attribute name="value-is-set">true</xsl:attribute>   135               </xsl:if>   136             </xsl:copy>   137           </xsl:for-each>   138         </screen>   139       </peripherals>   140     </xsl:copy>   141   </xsl:template>   142    143   <!-- Replicate unknown elements. -->   144    145   <xsl:template match="@*|node()">   146     <xsl:copy>   147       <xsl:apply-templates select="@*|node()"/>   148     </xsl:copy>   149   </xsl:template>   150    151 </xsl:stylesheet>