source: DCWoRMS/trunk/src/test/DEBBTranslator/xml/DCWoRMSDEBBUpdater.xsl @ 892

Revision 892, 7.9 KB checked in by gosiaw, 12 years ago (diff)

Some unnecessary code removed

Line 
1<?xml version="1.0" encoding="UTF-8"?>
2<xsl:stylesheet version="2.0"
3        xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dcworms="DCWormsResSchema.xsd"
4        xmlns:debb2dcworms="../../debb2dcworms.xsd">
5
6        <!-- Specification of the output document -->
7        <xsl:output method="xml" version="1.0" encoding="UTF-8"
8                indent="yes" />
9
10        <!-- Root of the DCWoRMS XML document -->
11        <xsl:variable name="rootDoc" select="/" />
12
13        <!-- Information about schedulers and estimators -->
14        <xsl:param name="additionalInformationFileName" select="additionalInformationFileName" />
15
16
17        <xsl:variable name="nestedDoc"
18                select="document($additionalInformationFileName)" />
19
20        <xsl:template match="/">
21                <xsl:comment>
22                        This is DEBB information (taken from PLM XML and DEBBComponent
23                        files), updated by schedulers and estimators. Moreover, all elements
24                        are sorted and appear in correct order, according to the schema.
25                </xsl:comment>
26                <xsl:comment>
27                        Schedulers and estimators information is loaded from
28                        <xsl:value-of select="$additionalInformationFileName" />
29                        file
30                </xsl:comment>
31
32                <xsl:apply-templates select="environment" />
33
34        </xsl:template>
35
36        <xsl:template match="environment">
37                <xsl:copy>
38                        <xsl:copy-of select="@*" />
39                        <xsl:apply-templates select="$nestedDoc//timeEstimationPlugin" />
40                        <xsl:apply-templates select="resources" />
41                </xsl:copy>
42        </xsl:template>
43
44        <xsl:template match="resources">
45                <xsl:copy copy-namespaces="no">
46                        <xsl:apply-templates select="//resources/computingResource" />
47                        <xsl:element name="scheduler">
48                                <xsl:attribute name="class">Cluster</xsl:attribute>
49                                <xsl:attribute name="name">cluster</xsl:attribute>
50                                <!-- In first version, for simplicity, we assume we have only one scheduler
51                                        and one scheduling plugin. If $additionalInformationFileName contains more
52                                        than one, the rest is ignored -->
53                                <xsl:apply-templates select="$nestedDoc//schedulingPlugin[1]" />
54                        </xsl:element>
55                </xsl:copy>
56        </xsl:template>
57
58        <xsl:template match="timeEstimationPlugin">
59                <xsl:element name="timeEstimationPlugin">
60                        <xsl:element name="name">
61                                <xsl:value-of select="name" />
62                        </xsl:element>
63                </xsl:element>
64        </xsl:template>
65
66
67        <xsl:template match="schedulingPlugin">
68                <xsl:variable name="pluginName" select="name" />
69                <xsl:element name="schedulingPlugin">
70                        <xsl:element name="name">
71                                <xsl:value-of select="$pluginName" />
72                        </xsl:element>
73                        <xsl:if test="frequency != ''">
74                                <xsl:element name="frequency">
75                                        <xsl:value-of select="frequency" />
76                                </xsl:element>
77                        </xsl:if>
78                </xsl:element>
79                <xsl:element name="managedComputingResources">
80                        <!-- TODO: This parameter should be taken from somewhere. -->
81                        <xsl:attribute name="include">false</xsl:attribute>
82
83                        <!-- Find appropriate resources (identified by class, type and name(s))
84                                and add their names here -->
85                        <xsl:variable name="resourceClass">
86                                <xsl:value-of select="resources/class" />
87                        </xsl:variable>
88                        <!-- <xsl:value-of select="$resourceClass"/> -->
89                        <xsl:variable name="resourceType">
90                                <xsl:value-of select="resources/type" />
91                        </xsl:variable>
92                        <!-- <xsl:value-of select="$resourceType"/> -->
93
94                        <!-- Not clear why it does not work this way :/ -->
95                        <!-- <xsl:variable name="resourceNames"><xsl:value-of select="resources/name"/></xsl:variable> -->
96                        <xsl:variable name="resourceNames"
97                                select="$nestedDoc//schedulingPlugin[name=$pluginName]/resources/name" />
98
99                        <xsl:choose>
100                                <!-- Resource names are present -->
101                                <xsl:when test="count($resourceNames) > 0">
102                                        <xsl:for-each select="$resourceNames">
103                                                <xsl:variable name="index" select="position()" />
104                                                <xsl:variable name="resourceName" select="." />
105                                                <xsl:choose>
106                                                        <!-- Resource type is present -->
107                                                        <xsl:when test="$resourceType != ''">
108                                                                <xsl:apply-templates
109                                                                        select="$rootDoc//computingResource[@class=$resourceClass and @type=$resourceType and @name=$resourceName]"
110                                                                        mode="addResorceName" />
111                                                        </xsl:when>
112                                                        <xsl:otherwise>
113                                                                <xsl:apply-templates
114                                                                        select="$rootDoc//computingResource[@class=$resourceClass and @name=$resourceName]"
115                                                                        mode="addResorceName" />
116                                                        </xsl:otherwise>
117                                                </xsl:choose>
118                                        </xsl:for-each>
119                                </xsl:when>
120                                <!-- No resource names -->
121                                <xsl:otherwise>
122                                        <xsl:choose>
123                                                <!-- Resource type is present -->
124                                                <xsl:when test="$resourceType != ''">
125                                                        <xsl:apply-templates
126                                                                select="$rootDoc//computingResource[@class=$resourceClass and @type=$resourceType]"
127                                                                mode="addResorceName" />
128                                                </xsl:when>
129                                                <xsl:otherwise>
130                                                        <xsl:apply-templates
131                                                                select="$rootDoc//computingResource[@class=$resourceClass]"
132                                                                mode="addResorceName" />
133                                                </xsl:otherwise>
134                                        </xsl:choose>
135                                </xsl:otherwise>
136                        </xsl:choose>
137                </xsl:element>
138        </xsl:template>
139
140        <xsl:template match="energyEstimationPlugin">
141                <xsl:element name="energyEstimationPlugin">
142                        <xsl:element name="name">
143                                <xsl:value-of select="name" />
144                        </xsl:element>
145                </xsl:element>
146        </xsl:template>
147
148        <xsl:template match="computingResource">
149                <xsl:copy copy-namespaces="no">
150                        <xsl:copy-of select="@*" />
151                        <!-- Find nested elements in appropriate order and copy them -->
152                        <!-- resourceUnit -->
153                        <xsl:apply-templates select="resourceUnit" />
154                        <!-- parameter -->
155                        <xsl:apply-templates select="parameter" />
156                        <!-- profile -->
157                        <xsl:apply-templates select="profile" />
158                        <!-- location -->
159                        <xsl:apply-templates select="location" />
160                        <!-- computingResource -->
161                        <xsl:apply-templates select="computingResource" />
162                </xsl:copy>
163        </xsl:template>
164
165        <xsl:template match="computingResource" mode="addResorceName">
166                <xsl:element name="resourceName">
167                        <!-- <xsl:value-of select="../@name"></xsl:value-of> -->
168                        <xsl:value-of select="@name"></xsl:value-of>
169                </xsl:element>
170        </xsl:template>
171       
172        <xsl:template match="resourceUnit | parameter | location">
173                <xsl:copy-of select="." copy-namespaces="no" />
174        </xsl:template>
175
176        <xsl:template match="profile">
177                <xsl:copy copy-namespaces="no">
178                        <xsl:copy-of select="@*" />
179                        <xsl:apply-templates select="powerProfile" />
180                </xsl:copy>
181        </xsl:template>
182
183        <xsl:template match="powerProfile">
184                <xsl:copy copy-namespaces="no">
185                        <xsl:variable name="resourceClass" select="../../@class"></xsl:variable>
186                        <xsl:variable name="resourceType" select="../../@type"></xsl:variable>
187                        <xsl:variable name="resourceNames" select="../../@name"></xsl:variable>
188
189                        <xsl:choose>
190                                <!-- Resource names are present -->
191                                <xsl:when test="count($resourceNames) > 0">
192                                        <xsl:for-each select="$resourceNames">
193                                                <xsl:variable name="index" select="position()" />
194                                                <xsl:variable name="resourceName" select="." />
195                                                <xsl:choose>
196                                                        <!-- Resource type is present -->
197                                                        <xsl:when test="$resourceType != ''">
198                                                                <xsl:apply-templates
199                                                                        select="$nestedDoc//energyEstimationPlugin[resources/class=$resourceClass and resources/type=$resourceType and resources/name=$resourceName]" />
200                                                        </xsl:when>
201                                                        <xsl:otherwise>
202                                                                <xsl:apply-templates
203                                                                        select="$nestedDoc//energyEstimationPlugin[resources/class=$resourceClass and resources/name=$resourceName]" />
204                                                        </xsl:otherwise>
205                                                </xsl:choose>
206                                        </xsl:for-each>
207                                </xsl:when>
208                                <!-- No resource names -->
209                                <xsl:otherwise>
210                                        <xsl:choose>
211                                                <!-- Resource type is present -->
212                                                <xsl:when test="$resourceType != ''">
213                                                        <xsl:apply-templates
214                                                                select="$nestedDoc//energyEstimationPlugin[resources/class=$resourceClass and resources/type=$resourceType]" />
215                                                </xsl:when>
216                                                <xsl:otherwise>
217                                                        <xsl:apply-templates
218                                                                select="$nestedDoc//energyEstimationPlugin[resources/class=$resourceClass]" />
219                                                </xsl:otherwise>
220                                        </xsl:choose>
221                                </xsl:otherwise>
222                        </xsl:choose>
223                        <!-- Copy all children of powerProfile -->
224                        <xsl:copy-of select="@*|node()" />
225                </xsl:copy>
226
227        </xsl:template>
228
229        <xsl:template match="@*|node()">
230                <xsl:copy>
231                        <xsl:apply-templates select="@*" />
232                        <xsl:apply-templates />
233                </xsl:copy>
234        </xsl:template>
235
236</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.