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 | xmlns:fun="http://whatever"> |
---|
6 | |
---|
7 | <!-- Specification of the output document --> |
---|
8 | <xsl:output method="xml" version="1.0" encoding="UTF-8" |
---|
9 | indent="yes" /> |
---|
10 | |
---|
11 | <!-- Root of the DCworms XML document --> |
---|
12 | <xsl:variable name="rootDoc" select="/" /> |
---|
13 | |
---|
14 | <xsl:param name="additionalInformationFileName" select="additionalInformationFileName" /> |
---|
15 | <xsl:param name="estimatorsInformationFileName" select="estimatorsInformationFileName" /> |
---|
16 | |
---|
17 | <xsl:variable name="nestedDoc" |
---|
18 | select="document($additionalInformationFileName)" /> |
---|
19 | |
---|
20 | <xsl:variable name="estimatorsDoc" |
---|
21 | select="document($estimatorsInformationFileName)" /> |
---|
22 | |
---|
23 | <xsl:template match="/"> |
---|
24 | <xsl:apply-templates select="environment" /> |
---|
25 | </xsl:template> |
---|
26 | |
---|
27 | <xsl:template match="environment"> |
---|
28 | <xsl:copy> |
---|
29 | <xsl:copy-of select="@*" /> |
---|
30 | <xsl:apply-templates select="timeEstimationPlugin" /> |
---|
31 | <xsl:apply-templates select="resources" /> |
---|
32 | <xsl:apply-templates select="templates"/> |
---|
33 | </xsl:copy> |
---|
34 | </xsl:template> |
---|
35 | |
---|
36 | <xsl:template match="resources"> |
---|
37 | <xsl:copy copy-namespaces="no"> |
---|
38 | <xsl:copy-of select="@*" /> |
---|
39 | <xsl:apply-templates select="//resources/computingResource" /> |
---|
40 | <xsl:apply-templates select="scheduler"/> |
---|
41 | </xsl:copy> |
---|
42 | </xsl:template> |
---|
43 | |
---|
44 | |
---|
45 | |
---|
46 | <xsl:template match="loadCalendar"> |
---|
47 | <xsl:element name="loadProfile"> |
---|
48 | <xsl:copy-of select="." copy-namespaces="no" /> |
---|
49 | </xsl:element> |
---|
50 | </xsl:template> |
---|
51 | |
---|
52 | |
---|
53 | <xsl:template match="computingResourceTemplate | computingResource"> |
---|
54 | <xsl:copy copy-namespaces="no"> |
---|
55 | <xsl:copy-of select="@*" /> |
---|
56 | <!-- Find nested elements in appropriate order and copy them --> |
---|
57 | |
---|
58 | <!-- templateId --> |
---|
59 | <xsl:apply-templates select="templateId" /> |
---|
60 | <!-- location --> |
---|
61 | <xsl:apply-templates select="location" /> |
---|
62 | <!-- parameter --> |
---|
63 | <xsl:apply-templates select="parameter" /> |
---|
64 | |
---|
65 | |
---|
66 | <xsl:variable name="resourceClass" select="@class"/> |
---|
67 | <xsl:variable name="resourceName" select="@name"/> |
---|
68 | <xsl:variable name="debbFullPath" select="fun:getFullPath(.)"/> |
---|
69 | |
---|
70 | <xsl:if test="not(templateId)"> |
---|
71 | <xsl:variable name="loadCalendar" select="fun:getLoadCalendar($resourceClass, $debbFullPath)"/> |
---|
72 | <xsl:variable name="hasProfile" select="profile != ''"/> |
---|
73 | |
---|
74 | <xsl:if test="$hasProfile = false() and $loadCalendar != ''"> |
---|
75 | <xsl:element name="profile"> |
---|
76 | <xsl:element name="loadProfile"> |
---|
77 | <xsl:element name="loadEstimationPlugin"> |
---|
78 | <xsl:element name="name"> |
---|
79 | <xsl:value-of select="fun:getLoadEstimator($resourceClass)"/> |
---|
80 | </xsl:element> |
---|
81 | </xsl:element> |
---|
82 | <xsl:copy-of |
---|
83 | select="$loadCalendar" /> |
---|
84 | </xsl:element> |
---|
85 | </xsl:element> |
---|
86 | </xsl:if> |
---|
87 | </xsl:if> |
---|
88 | |
---|
89 | <!-- profile --> |
---|
90 | <xsl:apply-templates select="profile" /> |
---|
91 | <!-- device --> |
---|
92 | <xsl:apply-templates select="device" /> |
---|
93 | <!-- resourceUnit --> |
---|
94 | <xsl:apply-templates select="resourceUnit" /> |
---|
95 | <!-- computingResource --> |
---|
96 | <xsl:apply-templates select="computingResource" /> |
---|
97 | |
---|
98 | </xsl:copy> |
---|
99 | </xsl:template> |
---|
100 | |
---|
101 | |
---|
102 | <xsl:function name="fun:getLoadCalendar"> |
---|
103 | <xsl:param name="computingResourceClass"/> |
---|
104 | <xsl:param name="computingResourceName"/> |
---|
105 | |
---|
106 | <xsl:variable name="loadCalendar" > |
---|
107 | <xsl:choose> |
---|
108 | <xsl:when test="$nestedDoc//computingResource[@class=$computingResourceClass and @name=$computingResourceName]"> |
---|
109 | <xsl:copy-of select="$nestedDoc//computingResource[@class=$computingResourceClass and @name=$computingResourceName]/loadCalendar"/> |
---|
110 | </xsl:when> |
---|
111 | <xsl:when test="$nestedDoc//computingResource[@class=$computingResourceClass]"> |
---|
112 | <xsl:copy-of select="$nestedDoc//computingResource[@class=$computingResourceClass and not(@name)]/loadCalendar"/> |
---|
113 | </xsl:when> |
---|
114 | <xsl:otherwise> |
---|
115 | </xsl:otherwise> |
---|
116 | </xsl:choose> |
---|
117 | </xsl:variable> |
---|
118 | <xsl:copy-of select="$loadCalendar"/> |
---|
119 | </xsl:function> |
---|
120 | |
---|
121 | <xsl:function name="fun:getLoadEstimator"> |
---|
122 | <xsl:param name="computingResourceClass"/> |
---|
123 | |
---|
124 | <xsl:variable name="estimatorName" > |
---|
125 | <xsl:choose> |
---|
126 | <xsl:when test="$estimatorsDoc//loadEstimationPlugin[resources/class=$computingResourceClass]/name !=''"> |
---|
127 | <xsl:value-of select="$estimatorsDoc//loadEstimationPlugin[resources/class=$computingResourceClass ]/name"/> |
---|
128 | </xsl:when> |
---|
129 | <xsl:otherwise> |
---|
130 | </xsl:otherwise> |
---|
131 | </xsl:choose> |
---|
132 | </xsl:variable> |
---|
133 | <xsl:value-of select="$estimatorName"/> |
---|
134 | </xsl:function> |
---|
135 | |
---|
136 | <xsl:template match="timeEstimationPlugin | scheduler | device | resourceUnit | parameter | location | powerProfile | airThroughputProfile"> |
---|
137 | <xsl:copy-of select="." copy-namespaces="no" /> |
---|
138 | </xsl:template> |
---|
139 | |
---|
140 | <xsl:function name="fun:getFullPath"> |
---|
141 | <xsl:param name="currentComputingResource"/> |
---|
142 | <xsl:variable name="ancestors" select="$currentComputingResource/ancestor::computingResource/@name"/> |
---|
143 | |
---|
144 | |
---|
145 | <xsl:variable name="fullPath"> |
---|
146 | <xsl:for-each select="1 to count($ancestors)"> |
---|
147 | <xsl:variable name="index" select="." /> |
---|
148 | <xsl:value-of select="$ancestors[$index]"/> |
---|
149 | <xsl:text>/</xsl:text> |
---|
150 | </xsl:for-each> |
---|
151 | <xsl:value-of select="$currentComputingResource/@name"></xsl:value-of> |
---|
152 | </xsl:variable> |
---|
153 | |
---|
154 | <xsl:value-of select="$fullPath"/> |
---|
155 | </xsl:function> |
---|
156 | |
---|
157 | <xsl:template match="profile"> |
---|
158 | <xsl:copy copy-namespaces="no"> |
---|
159 | <xsl:copy-of select="@*" /> |
---|
160 | |
---|
161 | <xsl:apply-templates select="powerProfile" /> |
---|
162 | <xsl:apply-templates select="airThroughputProfile" /> |
---|
163 | |
---|
164 | <xsl:variable name="resourceClass" select="../@class"></xsl:variable> |
---|
165 | <xsl:variable name="resourceName" select="../@name"></xsl:variable> |
---|
166 | <xsl:variable name="debbFullPath" select="fun:getFullPath(..)"/> |
---|
167 | |
---|
168 | <xsl:variable name="loadCalendar" select="fun:getLoadCalendar($resourceClass, $debbFullPath)"/> |
---|
169 | <xsl:if test="$loadCalendar != ''"> |
---|
170 | <xsl:element name="loadProfile"> |
---|
171 | <xsl:element name="loadEstimationPlugin"> |
---|
172 | <xsl:element name="name"> |
---|
173 | <xsl:value-of select="fun:getLoadEstimator($resourceClass)"/> |
---|
174 | </xsl:element> |
---|
175 | </xsl:element> |
---|
176 | <xsl:copy-of |
---|
177 | select="$loadCalendar" /> |
---|
178 | </xsl:element> |
---|
179 | </xsl:if> |
---|
180 | </xsl:copy> |
---|
181 | |
---|
182 | </xsl:template> |
---|
183 | |
---|
184 | |
---|
185 | <xsl:template match="templates"> |
---|
186 | <xsl:copy copy-namespaces="no"> |
---|
187 | <xsl:apply-templates/> |
---|
188 | </xsl:copy> |
---|
189 | |
---|
190 | </xsl:template> |
---|
191 | |
---|
192 | <xsl:template match="@*|node()"> |
---|
193 | <xsl:copy> |
---|
194 | <xsl:apply-templates select="@*" /> |
---|
195 | <xsl:apply-templates /> |
---|
196 | </xsl:copy> |
---|
197 | </xsl:template> |
---|
198 | |
---|
199 | </xsl:stylesheet> |
---|