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

Revision 890, 7.4 KB checked in by gosiaw, 12 years ago (diff)

Handling resource names added.

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><!-- <xsl:template match="powerProfile" mode="addEstimationPlugin">
171                <xsl:element name="energyEstimationPlugin"> <xsl:element name="name"> <xsl:value-of
172                select="name" /> </xsl:element> </xsl:element> </xsl:template> -->
173        <xsl:template match="resourceUnit | parameter | location">
174                <xsl:copy-of select="." copy-namespaces="no" />
175        </xsl:template>
176
177        <xsl:template match="profile">
178                <xsl:copy copy-namespaces="no">
179                        <xsl:copy-of select="@*" />
180                        <xsl:apply-templates select="powerProfile" />
181                </xsl:copy>
182        </xsl:template>
183
184        <xsl:template match="powerProfile">
185                <xsl:copy copy-namespaces="no">
186                        <xsl:variable name="resourceClass" select="../../@class"></xsl:variable>
187                        <xsl:variable name="resourceType" select="../../@type"></xsl:variable>
188                        <xsl:variable name="resourceName" select="../../@name"></xsl:variable>
189
190                        <xsl:choose>
191                                <xsl:when test="$resourceType != ''">
192                                        <!-- resource class and type -->
193                                        <!-- Add information about energy estimation plugin -->
194                                        <xsl:apply-templates
195                                                select="$nestedDoc//energyEstimationPlugin[resources/class = $resourceClass and resources/type = $resourceType]" />
196                                </xsl:when>
197                                <xsl:otherwise>
198                                        <!-- resource class only -->
199                                        <!-- Add information about energy estimation plugin -->
200                                        <xsl:apply-templates
201                                                select="$nestedDoc//energyEstimationPlugin[resources/class = $resourceClass]" />
202                                </xsl:otherwise>
203                        </xsl:choose>
204                        <!-- Copy all children of powerProfile -->
205                        <xsl:copy-of select="@*|node()" />
206                </xsl:copy>
207
208        </xsl:template>
209
210        <xsl:template match="@*|node()">
211                <xsl:copy>
212                        <xsl:apply-templates select="@*" />
213                        <xsl:apply-templates />
214                </xsl:copy>
215        </xsl:template>
216
217</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.