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:plm="http://www.plmxml.org/Schemas/PLMXMLSchema" |
---|
4 | xmlns:cim="http://www.coolemall.eu/DEBBComponent" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
---|
5 | xmlns:fun="http://whatever"> |
---|
6 | |
---|
7 | <!-- Importing xslt for translating debb components --> |
---|
8 | <xsl:import href="DEBBComponentTranslator.xsl" /> |
---|
9 | |
---|
10 | <!-- Information from which level the translator should start moving information to templates --> |
---|
11 | <xsl:param name="templateStartLevel" select="templateStartLevel" /> |
---|
12 | |
---|
13 | <xsl:param name="plmxmlFileName" select="plmxmlFileName" /> |
---|
14 | |
---|
15 | <!-- Specification of the output document --> |
---|
16 | <xsl:output method="xml" version="1.0" encoding="UTF-8" |
---|
17 | indent="yes" /> |
---|
18 | |
---|
19 | <!-- Root of the PLM XML document --> |
---|
20 | <xsl:variable name="rootDoc" select="/" /> |
---|
21 | |
---|
22 | |
---|
23 | |
---|
24 | <xsl:template match="/"> |
---|
25 | <xsl:element name="environment"> |
---|
26 | <xsl:attribute name="xsi:noNamespaceSchemaLocation">../DCwormsResSchema.xsd</xsl:attribute> |
---|
27 | |
---|
28 | <xsl:element name="resources"> |
---|
29 | <xsl:attribute name="mode">CoolEmAll</xsl:attribute> |
---|
30 | |
---|
31 | <!-- Iterate the document, create hierarchy and "links" to templates --> |
---|
32 | <xsl:apply-templates select="//plm:InstanceGraph" mode="createHierarchy"/> |
---|
33 | |
---|
34 | <!-- Create main scheduler --> |
---|
35 | <xsl:element name="scheduler"></xsl:element> |
---|
36 | </xsl:element> |
---|
37 | |
---|
38 | <!-- Create templates (if needed) --> |
---|
39 | <xsl:if test="fun:containsTemplates() = true()"> |
---|
40 | <xsl:element name="templates"> |
---|
41 | <!-- Iterate the document and createTemplates --> |
---|
42 | <xsl:apply-templates select="//plm:InstanceGraph" mode="createTemplates"/> |
---|
43 | </xsl:element> |
---|
44 | </xsl:if> |
---|
45 | |
---|
46 | </xsl:element> |
---|
47 | </xsl:template> |
---|
48 | |
---|
49 | <xsl:template match="plm:InstanceGraph" mode="createHierarchy"> |
---|
50 | <!-- Finding root DEBB --> |
---|
51 | <xsl:variable name="rootRef" select="@rootRefs" /> |
---|
52 | <xsl:apply-templates select="plm:ProductInstance[@id=$rootRef]" mode="createHierarchy"/> |
---|
53 | </xsl:template> |
---|
54 | |
---|
55 | <xsl:template match="plm:InstanceGraph" mode="createTemplates"> |
---|
56 | <xsl:apply-templates select="//plm:ProductRevisionView[plm:UserData/plm:UserValue/@title='DEBBLevel' and plm:UserData/plm:UserValue/@value=$templateStartLevel]" mode="createTemplates"/> |
---|
57 | |
---|
58 | |
---|
59 | </xsl:template> |
---|
60 | |
---|
61 | <xsl:template match="plm:ProductInstance" mode="createHierarchy"> |
---|
62 | <xsl:variable name="partRef" select="@partRef" /> |
---|
63 | <!-- Get rid of # at the beginning --> |
---|
64 | <xsl:variable name="productInstanceId" select="translate($partRef, '#', '')" /> |
---|
65 | |
---|
66 | <xsl:variable name="productInstanceType" select="../plm:ProductRevisionView[@id=$productInstanceId]/plm:UserData/plm:UserValue[@title='DEBBLevel']/@value"/> |
---|
67 | <xsl:if test="not ($productInstanceType = 'Sensor' or $productInstanceType ='Heatsink' or $productInstanceType ='Inlet' or $productInstanceType = 'Outlet' or $productInstanceType = 'CoolingDevice' or $productInstanceType ='Powersupply' or $productInstanceType ='Wall')"> |
---|
68 | <!-- We have to get rid of sensors, heatsinks, inlets, outlets, which make only problems here --> |
---|
69 | |
---|
70 | <xsl:element name="computingResource"> |
---|
71 | <xsl:attribute name="name"><xsl:value-of select="@name" /></xsl:attribute> |
---|
72 | |
---|
73 | <!-- Find corresponding ProductRevisionView and let it translate itself --> |
---|
74 | <xsl:apply-templates select="//plm:ProductRevisionView[@id=$productInstanceId]" mode="createHierarchy"/> |
---|
75 | |
---|
76 | <!-- Add hostnames, labels, locations, sequences, etc. --> |
---|
77 | <xsl:variable name="debbHostname" |
---|
78 | select="plm:UserData/plm:UserValue[@title='hostname']/@value" /> |
---|
79 | <xsl:if test="$debbHostname != ''"> |
---|
80 | <xsl:element name="parameter"> |
---|
81 | <xsl:attribute name="name">hostname</xsl:attribute> |
---|
82 | <xsl:element name="value"> |
---|
83 | <xsl:value-of select="$debbHostname" /> |
---|
84 | </xsl:element> |
---|
85 | </xsl:element> |
---|
86 | </xsl:if> |
---|
87 | |
---|
88 | </xsl:element> |
---|
89 | </xsl:if> |
---|
90 | <xsl:if test="$productInstanceType = 'CoolingDevice' or $productInstanceType ='Heatsink' or $productInstanceType ='Inlet' or $productInstanceType = 'Outlet'"> |
---|
91 | <xsl:element name="device"> |
---|
92 | <xsl:attribute name="name"> |
---|
93 | <xsl:value-of select="@name" /> |
---|
94 | </xsl:attribute> |
---|
95 | |
---|
96 | <!-- Find corresponding ProductRevisionView and let it translate itself --> |
---|
97 | <xsl:apply-templates select="//plm:ProductRevisionView[@id=$productInstanceId]" mode="createDevice"/> |
---|
98 | |
---|
99 | </xsl:element> |
---|
100 | </xsl:if> |
---|
101 | </xsl:template> |
---|
102 | |
---|
103 | |
---|
104 | <xsl:template match="plm:ProductRevisionView" mode="createHierarchy"> |
---|
105 | |
---|
106 | <!-- instanceRefs contain space separated ids of nested DEBBs --> |
---|
107 | <xsl:variable name="tokenizedText" select="tokenize(@instanceRefs, ' ')" /> |
---|
108 | |
---|
109 | <!-- DEBBLevel --> |
---|
110 | <xsl:variable name="debbLevel" |
---|
111 | select="plm:UserData/plm:UserValue[@title='DEBBLevel']/@value" /> |
---|
112 | <!-- DEBBComponentId --> |
---|
113 | <xsl:variable name="debbComponentId" |
---|
114 | select="plm:UserData/plm:UserValue[@title='DEBBComponentId']/@value" /> |
---|
115 | |
---|
116 | <xsl:variable name="debbComponentFile" |
---|
117 | select="plm:UserData/plm:UserValue[@title='DEBBComponentFile']/@value" /> |
---|
118 | |
---|
119 | |
---|
120 | <xsl:attribute name="class"> |
---|
121 | <xsl:value-of select="$debbLevel"/> |
---|
122 | </xsl:attribute> |
---|
123 | |
---|
124 | <xsl:choose> |
---|
125 | <xsl:when test="$debbLevel = $templateStartLevel"> |
---|
126 | <!-- Change into template. The rest of the hierarchy will be in a corresponding template. --> |
---|
127 | <xsl:element name="templateId"> |
---|
128 | <xsl:value-of select="$debbLevel"/> |
---|
129 | <xsl:text>-</xsl:text> |
---|
130 | <xsl:value-of select="$debbComponentId"/> |
---|
131 | </xsl:element> |
---|
132 | </xsl:when> |
---|
133 | <xsl:otherwise> |
---|
134 | |
---|
135 | <!-- Read information from DEBBComponent file --> |
---|
136 | <xsl:choose> |
---|
137 | <!-- DEBB Components file is defined --> |
---|
138 | <xsl:when test="$debbComponentFile != ''"> |
---|
139 | <xsl:variable name="nestedDoc" select="document($debbComponentFile)" /> |
---|
140 | <xsl:apply-templates select="$nestedDoc//*[ComponentId=$debbComponentId]" mode="component"> |
---|
141 | <xsl:with-param name="instanceRefs" select="@instanceRefs" /> |
---|
142 | </xsl:apply-templates> |
---|
143 | </xsl:when> |
---|
144 | |
---|
145 | </xsl:choose> |
---|
146 | |
---|
147 | <!-- Iterate children and ask them to translate themselves --> |
---|
148 | <xsl:for-each select="1 to count($tokenizedText)"> |
---|
149 | <xsl:variable name="index" select="." /> |
---|
150 | <xsl:apply-templates |
---|
151 | select="$rootDoc//plm:ProductInstance[@id=$tokenizedText[$index]]" mode="createHierarchy"/> |
---|
152 | </xsl:for-each> |
---|
153 | </xsl:otherwise> |
---|
154 | </xsl:choose> |
---|
155 | </xsl:template> |
---|
156 | |
---|
157 | |
---|
158 | <xsl:template match="plm:ProductRevisionView" mode="createDevice"> |
---|
159 | |
---|
160 | <!-- DEBBLevel --> |
---|
161 | <xsl:variable name="debbLevel" |
---|
162 | select="plm:UserData/plm:UserValue[@title='DEBBLevel']/@value" /> |
---|
163 | <!-- DEBBComponentId --> |
---|
164 | <xsl:variable name="debbComponentId" |
---|
165 | select="plm:UserData/plm:UserValue[@title='DEBBComponentId']/@value" /> |
---|
166 | |
---|
167 | <xsl:variable name="debbComponentFile" |
---|
168 | select="plm:UserData/plm:UserValue[@title='DEBBComponentFile']/@value" /> |
---|
169 | |
---|
170 | |
---|
171 | <xsl:attribute name="class"> |
---|
172 | <xsl:value-of select="$debbLevel"/> |
---|
173 | </xsl:attribute> |
---|
174 | |
---|
175 | <!-- DEBB Components file is defined --> |
---|
176 | <xsl:if test="$debbComponentFile != ''"> |
---|
177 | <xsl:variable name="nestedDoc" select="document($debbComponentFile)" /> |
---|
178 | |
---|
179 | <xsl:if test="$debbLevel = 'CoolingDevice'"> |
---|
180 | <xsl:apply-templates select="$nestedDoc//*[ComponentId=$debbComponentId]" mode="coolingDevice"> |
---|
181 | <xsl:with-param name="instanceRefs" select="@id" /> |
---|
182 | </xsl:apply-templates> |
---|
183 | </xsl:if> |
---|
184 | <xsl:if test="$debbLevel = 'Inlet' or $debbLevel = 'Outlet'"> |
---|
185 | <xsl:apply-templates select="$nestedDoc//*[ComponentId=$debbComponentId]" mode="fan"> |
---|
186 | <xsl:with-param name="instanceRefs" select="@id" /> |
---|
187 | </xsl:apply-templates> |
---|
188 | </xsl:if> |
---|
189 | <xsl:if test="$debbLevel = 'Heatsink'"> |
---|
190 | <xsl:apply-templates select="$nestedDoc//*[ComponentId=$debbComponentId]" mode="heatsink"> |
---|
191 | <xsl:with-param name="instanceRefs" select="@id" /> |
---|
192 | </xsl:apply-templates> |
---|
193 | </xsl:if> |
---|
194 | </xsl:if> |
---|
195 | </xsl:template> |
---|
196 | |
---|
197 | <xsl:template match="plm:ProductRevisionView" mode="createTemplates"> |
---|
198 | |
---|
199 | <!-- instanceRefs contain space separated ids of nested DEBBs --> |
---|
200 | <xsl:variable name="tokenizedText" select="tokenize(@instanceRefs, ' ')" /> |
---|
201 | |
---|
202 | <xsl:variable name="debbLevel" |
---|
203 | select="plm:UserData/plm:UserValue[@title='DEBBLevel']/@value" /> |
---|
204 | |
---|
205 | <xsl:variable name="debbComponentId" |
---|
206 | select="plm:UserData/plm:UserValue[@title='DEBBComponentId']/@value" /> |
---|
207 | |
---|
208 | <xsl:variable name="debbComponentFile" |
---|
209 | select="plm:UserData/plm:UserValue[@title='DEBBComponentFile']/@value" /> |
---|
210 | |
---|
211 | |
---|
212 | <xsl:if test="$debbLevel"> |
---|
213 | <xsl:element name="computingResourceTemplate"> |
---|
214 | <xsl:attribute name="name"> |
---|
215 | <xsl:value-of select="$debbLevel"/> |
---|
216 | <xsl:text>-</xsl:text> |
---|
217 | <xsl:value-of select="$debbComponentId"/> |
---|
218 | </xsl:attribute> |
---|
219 | <xsl:attribute name="class"> |
---|
220 | <xsl:value-of select="$debbLevel"/> |
---|
221 | </xsl:attribute> |
---|
222 | |
---|
223 | <!-- Read information from DEBBComponent file --> |
---|
224 | <xsl:choose> |
---|
225 | <!-- DEBB Components file is defined --> |
---|
226 | <xsl:when test="$debbComponentFile != ''"> |
---|
227 | <xsl:variable name="nestedDoc" select="document($debbComponentFile)" /> |
---|
228 | |
---|
229 | <xsl:apply-templates select="$nestedDoc//*[ComponentId=$debbComponentId]" mode="component"> |
---|
230 | <xsl:with-param name="instanceRefs" select="@instanceRefs" /> |
---|
231 | </xsl:apply-templates> |
---|
232 | |
---|
233 | </xsl:when> |
---|
234 | |
---|
235 | </xsl:choose> |
---|
236 | |
---|
237 | <!-- Iterate children and ask them to translate themselves --> |
---|
238 | <xsl:for-each select="1 to count($tokenizedText)"> |
---|
239 | <xsl:variable name="index" select="." /> |
---|
240 | <xsl:apply-templates |
---|
241 | select="$rootDoc//plm:ProductInstance[@id=$tokenizedText[$index]]" mode="createHierarchy"/> |
---|
242 | </xsl:for-each> |
---|
243 | |
---|
244 | </xsl:element> |
---|
245 | </xsl:if> |
---|
246 | </xsl:template> |
---|
247 | |
---|
248 | <xsl:template match="plm:ProductInstance" mode="updateHeatsinkDevice"> |
---|
249 | |
---|
250 | <xsl:variable name="power-sensor" |
---|
251 | select="plm:UserData/plm:UserValue[@title='power-sensor']/@value" /> |
---|
252 | <xsl:choose> |
---|
253 | <xsl:when test="$power-sensor != ''"> |
---|
254 | <xsl:element name="parameter"> |
---|
255 | <xsl:attribute name="name">power-sensor</xsl:attribute> |
---|
256 | <xsl:element name="value"> |
---|
257 | <xsl:value-of select="$power-sensor" /> |
---|
258 | </xsl:element> |
---|
259 | </xsl:element> |
---|
260 | </xsl:when> |
---|
261 | <xsl:otherwise> |
---|
262 | <xsl:element name="parameter"> |
---|
263 | <xsl:attribute name="name">power-sensor</xsl:attribute> |
---|
264 | <xsl:element name="value">power</xsl:element> |
---|
265 | </xsl:element> |
---|
266 | </xsl:otherwise> |
---|
267 | </xsl:choose> |
---|
268 | |
---|
269 | <!-- |
---|
270 | <xsl:variable name="temperature-sensor" |
---|
271 | select="plm:UserData/plm:UserValue[@title='temperature-sensor']/@value" /> |
---|
272 | <xsl:choose> |
---|
273 | <xsl:when test="$temperature-sensor != ''"> |
---|
274 | <xsl:element name="parameter"> |
---|
275 | <xsl:attribute name="name">temperature-sensor</xsl:attribute> |
---|
276 | <xsl:element name="value"> |
---|
277 | <xsl:value-of select="$temperature-sensor" /> |
---|
278 | </xsl:element> |
---|
279 | </xsl:element> |
---|
280 | </xsl:when> |
---|
281 | <xsl:otherwise> |
---|
282 | <xsl:element name="parameter"> |
---|
283 | <xsl:attribute name="name">temperature-sensor</xsl:attribute> |
---|
284 | <xsl:element name="value">temperature</xsl:element> |
---|
285 | </xsl:element> |
---|
286 | </xsl:otherwise> |
---|
287 | </xsl:choose> |
---|
288 | --> |
---|
289 | </xsl:template> |
---|
290 | |
---|
291 | <xsl:template match="plm:ProductInstance" mode="updateCoolingDevice"> |
---|
292 | |
---|
293 | <xsl:variable name="airflow_volume-sensor" |
---|
294 | select="plm:UserData/plm:UserValue[@title='airflow_volume-sensor']/@value" /> |
---|
295 | <xsl:choose> |
---|
296 | <xsl:when test="$airflow_volume-sensor != ''"> |
---|
297 | <xsl:element name="parameter"> |
---|
298 | <xsl:attribute name="name">airflow_volume-sensor</xsl:attribute> |
---|
299 | <xsl:element name="value"> |
---|
300 | <xsl:value-of select="$airflow_volume-sensor" /> |
---|
301 | </xsl:element> |
---|
302 | </xsl:element> |
---|
303 | </xsl:when> |
---|
304 | <xsl:otherwise> |
---|
305 | <xsl:element name="parameter"> |
---|
306 | <xsl:attribute name="name">airflow_volume-sensor</xsl:attribute> |
---|
307 | <xsl:element name="value">airflow_volume</xsl:element> |
---|
308 | </xsl:element> |
---|
309 | </xsl:otherwise> |
---|
310 | </xsl:choose> |
---|
311 | |
---|
312 | <xsl:variable name="airflow_speed-sensor" |
---|
313 | select="plm:UserData/plm:UserValue[@title='airflow_speed-sensor']/@value" /> |
---|
314 | <xsl:choose> |
---|
315 | <xsl:when test="$airflow_speed-sensor != ''"> |
---|
316 | <xsl:element name="parameter"> |
---|
317 | <xsl:attribute name="name">airflow_speed-sensor</xsl:attribute> |
---|
318 | <xsl:element name="value"> |
---|
319 | <xsl:value-of select="$airflow_speed-sensor" /> |
---|
320 | </xsl:element> |
---|
321 | </xsl:element> |
---|
322 | </xsl:when> |
---|
323 | <xsl:otherwise> |
---|
324 | <xsl:element name="parameter"> |
---|
325 | <xsl:attribute name="name">airflow_speed-sensor</xsl:attribute> |
---|
326 | <xsl:element name="value">airflow_speed</xsl:element> |
---|
327 | </xsl:element> |
---|
328 | </xsl:otherwise> |
---|
329 | </xsl:choose> |
---|
330 | |
---|
331 | <xsl:variable name="temperature-sensor" |
---|
332 | select="plm:UserData/plm:UserValue[@title='temperature-sensor']/@value" /> |
---|
333 | <xsl:choose> |
---|
334 | <xsl:when test="$temperature-sensor != ''"> |
---|
335 | <xsl:element name="parameter"> |
---|
336 | <xsl:attribute name="name">temperature-sensor</xsl:attribute> |
---|
337 | <xsl:element name="value"> |
---|
338 | <xsl:value-of select="$temperature-sensor" /> |
---|
339 | </xsl:element> |
---|
340 | </xsl:element> |
---|
341 | </xsl:when> |
---|
342 | <xsl:otherwise> |
---|
343 | <xsl:element name="parameter"> |
---|
344 | <xsl:attribute name="name">temperature-sensor</xsl:attribute> |
---|
345 | <xsl:element name="value">temperature</xsl:element> |
---|
346 | </xsl:element> |
---|
347 | </xsl:otherwise> |
---|
348 | </xsl:choose> |
---|
349 | </xsl:template> |
---|
350 | |
---|
351 | <xsl:function name="fun:containsTemplates"> |
---|
352 | <xsl:variable name="productRevisionViews" select="$rootDoc//plm:ProductRevisionView[plm:UserData/plm:UserValue/@title='DEBBLevel' and plm:UserData/plm:UserValue/@value=$templateStartLevel]"/> |
---|
353 | <xsl:variable name="numberOfTemplates" select="count($productRevisionViews)"/> |
---|
354 | |
---|
355 | <xsl:value-of select="$numberOfTemplates > 0"/> |
---|
356 | </xsl:function> |
---|
357 | |
---|
358 | </xsl:stylesheet> |
---|
359 | |
---|