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

Revision 889, 6.6 KB checked in by gosiaw, 12 years ago (diff)

Ignoring scheduling plugins, it there are more than one.

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
51                                 one scheduler and one scheduling plugin. If $additionalInformationFileName
52                                 contains more 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:element name="schedulingPlugin">
69                        <xsl:element name="name">
70                                <xsl:value-of select="name" />
71                        </xsl:element>
72                        <xsl:if test="frequency != ''">
73                                <xsl:element name="frequency">
74                                        <xsl:value-of select="frequency"/>
75                                </xsl:element>
76                        </xsl:if>
77                </xsl:element>
78                <xsl:element name="managedComputingResources">
79                        <!-- TODO: This parameter should be taken from somewhere. -->
80                        <xsl:attribute name="include">false</xsl:attribute>
81                       
82                        <!-- Find appropriate resources (identified by class, type and name(s)) and add their names here -->
83                        <xsl:variable name="resourceClass"><xsl:value-of select="resources/class"/></xsl:variable>
84<!--                    <xsl:value-of select="$resourceClass"/>-->
85                        <xsl:variable name="resourceType"><xsl:value-of select="resources/type"/></xsl:variable>
86<!--                    <xsl:value-of select="$resourceType"/>-->
87                        <xsl:variable name="resourceNames"><xsl:value-of select="resources/name"/></xsl:variable>
88                        <xsl:variable name="xpath">$rootDoc//computingResource[@class=<xsl:value-of select="$resourceClass"/> and @type=<xsl:value-of select="$resourceType"/>]</xsl:variable>
89<!--                    <xsl:value-of select="$xpath"></xsl:value-of>-->
90
91                        <!-- TODO: Names are ignored now, for simplicity. Should be changed! -->
92                        <xsl:choose>
93                                <xsl:when test="$resourceClass != '' and $resourceType != ''">
94<!--                                    <xsl:value-of select="$resourceClass"/>-->
95<!--                                    <xsl:value-of select="$resourceType"/>-->
96                                        <xsl:apply-templates select="$rootDoc//computingResource[@class=$resourceClass and @type=$resourceType]" mode="addResorceName"/>
97                                </xsl:when>
98                                <xsl:otherwise>
99<!--                                    <xsl:value-of select="$resourceClass"/>-->
100                                        <xsl:apply-templates select="$rootDoc//computingResource[@class=$resourceClass]" mode="addResorceName"/>
101                                </xsl:otherwise>
102                        </xsl:choose>
103                       
104                       
105                       
106                </xsl:element>
107        </xsl:template>
108
109        <xsl:template match="energyEstimationPlugin">
110                <xsl:element name="energyEstimationPlugin">
111                        <xsl:element name="name">
112                                <xsl:value-of select="name" />
113                        </xsl:element>
114                </xsl:element>
115        </xsl:template>
116       
117        <xsl:template match="computingResource">
118                <xsl:copy copy-namespaces="no">
119                        <xsl:copy-of select="@*" />
120                        <!-- Find nested elements in appropriate order and copy them -->
121                        <!-- resourceUnit -->
122                        <xsl:apply-templates select="resourceUnit" />
123                        <!-- parameter -->
124                        <xsl:apply-templates select="parameter" />
125                        <!-- profile -->
126                        <xsl:apply-templates select="profile" />               
127                        <!-- location -->
128                        <xsl:apply-templates select="location" />
129                        <!-- computingResource -->
130                        <xsl:apply-templates select="computingResource" />
131                </xsl:copy>
132        </xsl:template>
133
134        <xsl:template match="computingResource" mode="addResorceName">
135                <xsl:element name="resourceName">
136                        <xsl:value-of select="../@name"></xsl:value-of>
137                </xsl:element>
138        </xsl:template><!--
139       
140        <xsl:template match="powerProfile" mode="addEstimationPlugin">
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="resourceUnit | parameter | location">
149                <xsl:copy-of select="." copy-namespaces="no" />
150        </xsl:template>
151
152        <xsl:template match="profile">
153                <xsl:copy copy-namespaces="no">
154                        <xsl:copy-of select="@*" />
155                        <xsl:apply-templates select="powerProfile" />
156                </xsl:copy>                                     
157        </xsl:template>
158
159        <xsl:template match="powerProfile">     
160                <xsl:copy copy-namespaces="no">
161                        <xsl:variable name="resourceClass" select="../../@class"></xsl:variable>
162                        <xsl:variable name="resourceType" select="../../@type"></xsl:variable>
163                        <xsl:variable name="resourceName" select="../../@name"></xsl:variable>
164                       
165                        <xsl:choose>
166                                <xsl:when test="$resourceType != ''">
167                                        <!-- resource class and type -->
168                                        <!-- Add information about energy estimation plugin -->
169                                        <xsl:apply-templates select="$nestedDoc//energyEstimationPlugin[resources/class = $resourceClass and resources/type = $resourceType]"/>                                 
170                                </xsl:when>
171                                <xsl:otherwise>
172                                        <!-- resource class only -->
173                                        <!-- Add information about energy estimation plugin -->
174                                        <xsl:apply-templates select="$nestedDoc//energyEstimationPlugin[resources/class = $resourceClass]"/>                                   
175                                </xsl:otherwise>
176                        </xsl:choose>
177                        <!-- Copy all children of powerProfile -->
178                        <xsl:copy-of select="@*|node()" />             
179                </xsl:copy>     
180               
181        </xsl:template> 
182       
183         <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*"/> 
184                <xsl:apply-templates/> </xsl:copy> </xsl:template> 
185
186</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.