source: DCWoRMS/branches/coolemall/simulator/xslt/debb/PLMXMLTranslator.xsl @ 1302

Revision 1302, 17.0 KB checked in by wojtekp, 11 years ago (diff)
  • Property svn:mime-type set to text/plain
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: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="plmxmlFolderName" select="plmxmlFolderName" />
14        <xsl:param name="plmxmlFileName" select="plmxmlFileName" />
15               
16        <!-- Specification of the output document -->
17        <xsl:output method="xml" version="1.0" encoding="UTF-8"
18                indent="yes" />
19
20        <!-- Root of the PLM XML document -->
21        <xsl:variable name="rootDoc" select="/" />
22
23
24
25        <xsl:template match="/">
26                <xsl:element name="environment">
27                        <xsl:attribute name="xsi:noNamespaceSchemaLocation">../DCwormsResSchema.xsd</xsl:attribute>
28                       
29                        <xsl:element name="resources">
30                                <xsl:attribute name="mode">CoolEmAll</xsl:attribute>
31                       
32                                <!-- Iterate the document, create hierarchy and "links" to templates -->
33                                <xsl:apply-templates select="//plm:InstanceGraph" mode="createHierarchy"/>
34                                                               
35                                <!-- Create main scheduler -->
36                                <xsl:element name="scheduler"></xsl:element>
37                        </xsl:element>
38                       
39                        <!-- Create templates (if needed) -->
40                        <xsl:if test="fun:containsTemplates() = true()">
41                                <xsl:element name="templates">
42                                        <!-- Iterate the document and createTemplates -->
43                                        <xsl:apply-templates select="//plm:InstanceGraph" mode="createTemplates"/>
44                                </xsl:element>                 
45                        </xsl:if>
46                       
47                </xsl:element>
48        </xsl:template>
49
50        <xsl:template match="plm:InstanceGraph" mode="createHierarchy">
51                <!-- Finding root DEBB -->
52                <xsl:variable name="rootRef" select="@rootRefs" />
53                <xsl:apply-templates select="plm:ProductInstance[@id=$rootRef]" mode="createHierarchy"/>
54        </xsl:template>
55
56        <xsl:template match="plm:InstanceGraph" mode="createTemplates">
57                        <xsl:variable name="rootRef" select="@rootRefs" />
58                <xsl:apply-templates select="//plm:ProductInstance[@id=$rootRef]" mode="createTemplates"/>
59           
60        </xsl:template>
61
62        <xsl:template match="plm:ProductInstance" mode="createTemplates">
63
64                <xsl:variable name="nodesTemplates" select="distinct-values(//plm:ProductRevisionView[plm:UserData/plm:UserValue/@value=$templateStartLevel]/plm:UserData/plm:UserValue[@title='DEBBComponentFile']/@value)"/>
65                <xsl:for-each select="1 to count($nodesTemplates)">
66                        <xsl:variable name="index" select="." />
67                        <xsl:variable name="debbFileName" select="$nodesTemplates[$index]"/>
68                        <xsl:variable name="nodesTemplatesIds" select="distinct-values($rootDoc//plm:ProductRevisionView[plm:UserData/plm:UserValue/@value=$debbFileName]/plm:UserData/plm:UserValue[@title='DEBBComponentId']/@value)"/>
69                        <xsl:for-each select="1 to count($nodesTemplatesIds)">
70                                <xsl:variable name="index2" select="." />
71                                <xsl:variable name="debbFileFullName">
72                                        <xsl:value-of select="$plmxmlFolderName"/>
73                                                <xsl:text>/</xsl:text>
74                                        <xsl:value-of select="$debbFileName"/>
75                                </xsl:variable>
76                                <xsl:variable name="nestedDoc" select="document($debbFileFullName)" />
77                                <xsl:variable name="debbComponentId" select="$nodesTemplatesIds[$index2]"/>
78                               
79                                        <xsl:variable name="instancesReferences" select="distinct-values($rootDoc//plm:ProductRevisionView[plm:UserData/plm:UserValue/@value=$debbFileName and plm:UserData/plm:UserValue/@value=$debbComponentId]/@instanceRefs)"/>
80
81                                        <xsl:variable name="partsReferences" select="distinct-values($rootDoc//plm:ProductInstance[@id=($instancesReferences)]/@partRef)"/>
82
83                                        <xsl:variable name="devicesIds" select="distinct-values($rootDoc//plm:ProductRevisionView[@id=($partsReferences)]/plm:UserData/plm:UserValue[@title='DEBBComponentId']/@value)"/>
84                                       
85                                        <xsl:for-each select="1 to count($devicesIds)">
86                                                <xsl:variable name="index3" select="." />
87                                                <xsl:element name="computingResourceTemplate">
88                                                <xsl:attribute name="name">
89                                                        <xsl:value-of select="$templateStartLevel"/>
90                                                        <xsl:text>-</xsl:text>
91                                                        <xsl:value-of select="$debbComponentId"/>
92                                                </xsl:attribute>
93                                                <xsl:attribute name="class">
94                                                        <xsl:value-of select="$templateStartLevel"/>
95                                                </xsl:attribute>
96                                                <xsl:apply-templates select="$nestedDoc//*[PartID=$debbComponentId]" mode="component"/>         
97                                                <xsl:element name="device">
98                                                <xsl:variable name="deviceName" select="distinct-values($rootDoc//plm:ProductRevisionView[plm:UserData/plm:UserValue/@value=$devicesIds[$index3]]/@name)[1]" />         
99                                                                                <xsl:attribute name="name">
100                                        <xsl:value-of select="$deviceName" />
101                                </xsl:attribute>
102                                        <xsl:variable name="deviceClass" select="distinct-values($rootDoc//plm:ProductRevisionView[plm:UserData/plm:UserValue/@value=$devicesIds[$index3]]/plm:UserData/plm:UserValue[@title='DEBBLevel']/@value)[1]" />               
103                                                                                <xsl:attribute name="class">
104                                                        <xsl:value-of select="$deviceClass"/>
105                                                </xsl:attribute>
106                                                        <xsl:variable name="devicesTemplates" select="distinct-values($rootDoc//plm:ProductRevisionView[plm:UserData/plm:UserValue/@value=$devicesIds[$index3]]/plm:UserData/plm:UserValue[@title='DEBBComponentFile']/@value)"/>
107                                                       
108                                                        <xsl:for-each select="1 to count($devicesTemplates)">
109                                                                <xsl:variable name="index4" select="." />
110                                                                                                <xsl:variable name="deviceFileFullName">
111                                        <xsl:value-of select="$plmxmlFolderName"/>
112                                                <xsl:text>/</xsl:text>
113                                        <xsl:value-of select="$devicesTemplates[$index4]"/>
114                                </xsl:variable>
115                                                                <xsl:variable name="nestedDoc2" select="document($deviceFileFullName)" />
116                                                                <xsl:apply-templates select="$nestedDoc2//*[PartID=$devicesIds[$index3]]" mode="heatsink">
117                                                <xsl:with-param name="instanceRefs" select="distinct-values($rootDoc//plm:ProductRevisionView[plm:UserData/plm:UserValue/@value=$devicesIds[$index3]]/@id)[1]" />               
118                                                        </xsl:apply-templates>
119                                                                </xsl:for-each>
120                                                </xsl:element>
121                                        </xsl:element>
122                                       
123                                                                               
124                                        </xsl:for-each>
125
126                        </xsl:for-each>
127                </xsl:for-each>
128        </xsl:template>
129       
130        <xsl:template match="plm:ProductInstance" mode="createHierarchy">
131                <xsl:variable name="partRef" select="@partRef" />
132                <!-- Get rid of # at the beginning -->
133                <xsl:variable name="productInstanceId" select="translate($partRef, '#', '')" />
134
135                <xsl:variable name="productInstanceType" select="../plm:ProductRevisionView[@id=$productInstanceId]/plm:UserData/plm:UserValue[@title='DEBBLevel']/@value"/>
136                <xsl:if test="not ($productInstanceType = 'Sensor' or $productInstanceType ='Heatsink' or $productInstanceType ='Inlet' or $productInstanceType = 'Outlet' or $productInstanceType = 'CoolingDevice' or $productInstanceType ='Powersupply' or $productInstanceType ='Wall')">
137                        <!-- We have to get rid of sensors, heatsinks, inlets, outlets, which make only problems here -->
138                                               
139                        <xsl:element name="computingResource">
140                                <xsl:attribute name="name"><xsl:value-of select="@name" /></xsl:attribute>
141
142                                <!-- Find corresponding ProductRevisionView and let it translate itself -->
143                                <xsl:apply-templates select="//plm:ProductRevisionView[@id=$productInstanceId]" mode="createHierarchy"/>
144
145                                <!-- Add hostnames, labels, locations, sequences, etc. -->
146                                <xsl:variable name="debbHostname"
147                                        select="plm:UserData/plm:UserValue[@title='hostname']/@value" />
148                                <xsl:if test="$debbHostname != ''">
149                                        <xsl:element name="parameter">
150                                                <xsl:attribute name="name">hostname</xsl:attribute>
151                                                <xsl:element name="value">
152                                                        <xsl:value-of select="$debbHostname" />
153                                                </xsl:element>
154                                        </xsl:element>
155                                </xsl:if>
156
157                        </xsl:element>
158                </xsl:if>
159                <xsl:if test="$productInstanceType = 'CoolingDevice' or $productInstanceType ='Heatsink' or $productInstanceType ='Inlet' or $productInstanceType = 'Outlet'">
160                        <xsl:element name="device">
161                                <xsl:attribute name="name">
162                                        <xsl:value-of select="@name" />
163                                </xsl:attribute>
164
165                                <!-- Find corresponding ProductRevisionView and let it translate itself -->
166                                <xsl:apply-templates select="//plm:ProductRevisionView[@id=$productInstanceId]" mode="createDevice"/>
167                                       
168                        </xsl:element>
169                </xsl:if>               
170        </xsl:template>
171       
172
173        <xsl:template match="plm:ProductRevisionView" mode="createHierarchy">
174
175                <!-- instanceRefs contain space separated ids of nested DEBBs -->
176                <xsl:variable name="tokenizedText" select="tokenize(@instanceRefs, ' ')" />
177       
178                <!-- DEBBLevel -->
179                <xsl:variable name="debbLevel"
180                        select="plm:UserData/plm:UserValue[@title='DEBBLevel']/@value" />
181                <!-- DEBBComponentId -->
182                <xsl:variable name="debbComponentId"
183                        select="plm:UserData/plm:UserValue[@title='DEBBComponentId']/@value" />
184
185                <xsl:variable name="debbComponentFile"
186                        select="plm:UserData/plm:UserValue[@title='DEBBComponentFile']/@value" />
187
188                                       
189                <xsl:attribute name="class">
190                        <xsl:value-of select="$debbLevel"/>
191                </xsl:attribute>
192               
193                <xsl:choose>
194                        <xsl:when test="$debbLevel = $templateStartLevel">
195                                <!-- Change into template. The rest of the hierarchy will be in a corresponding template. -->
196                                <xsl:element name="templateId">
197                                        <xsl:value-of select="$debbLevel"/>
198                                        <xsl:text>-</xsl:text>
199                                        <xsl:value-of select="$debbComponentId"/>
200                                </xsl:element>         
201                        </xsl:when>
202                        <xsl:otherwise>
203                       
204                                <!-- Read information from DEBBComponent file -->       
205                                <xsl:choose>
206                                         <!-- DEBB Components file is defined  -->
207                                        <xsl:when test="$debbComponentFile != ''">
208                                                <xsl:variable name="nestedDoc" select="document($debbComponentFile)" />
209                                                <xsl:apply-templates select="$nestedDoc//*[PartID=$debbComponentId]" mode="component">
210                                                        <xsl:with-param name="instanceRefs" select="@instanceRefs" />           
211                                                </xsl:apply-templates>
212                                        </xsl:when>
213
214                                </xsl:choose>                   
215                       
216                                <!-- Iterate children and ask them to translate themselves -->
217                                <xsl:for-each select="1 to count($tokenizedText)">
218                                        <xsl:variable name="index" select="." />
219                                        <xsl:apply-templates
220                                                select="$rootDoc//plm:ProductInstance[@id=$tokenizedText[$index]]" mode="createHierarchy"/>
221                                </xsl:for-each>                 
222                        </xsl:otherwise>
223                </xsl:choose>
224        </xsl:template>
225       
226       
227        <xsl:template match="plm:ProductRevisionView" mode="createDevice">
228       
229                <!-- DEBBLevel -->
230                <xsl:variable name="debbLevel"
231                        select="plm:UserData/plm:UserValue[@title='DEBBLevel']/@value" />
232                <!-- DEBBComponentId -->
233                <xsl:variable name="debbComponentId"
234                        select="plm:UserData/plm:UserValue[@title='DEBBComponentId']/@value" />
235
236                <xsl:variable name="debbComponentFile"
237                        select="plm:UserData/plm:UserValue[@title='DEBBComponentFile']/@value" />
238
239                                       
240                <xsl:attribute name="class">
241                        <xsl:value-of select="$debbLevel"/>
242                </xsl:attribute>
243
244                 <!-- DEBB Components file is defined  -->
245                <xsl:if test="$debbComponentFile != ''">
246                        <xsl:variable name="nestedDoc" select="document($debbComponentFile)" />
247
248                        <xsl:if test="$debbLevel = 'CoolingDevice'">
249                                <xsl:apply-templates select="$nestedDoc//*[PartID=$debbComponentId]" mode="coolingDevice">
250                                        <xsl:with-param name="instanceRefs" select="@id" />             
251                                </xsl:apply-templates>
252                        </xsl:if>       
253                        <xsl:if test="$debbLevel = 'Inlet' or $debbLevel = 'Outlet'">
254                                <xsl:apply-templates select="$nestedDoc//*[PartID=$debbComponentId]" mode="fan">
255                                        <xsl:with-param name="instanceRefs" select="@id" />             
256                                </xsl:apply-templates>
257                        </xsl:if>
258                        <xsl:if test="$debbLevel = 'Heatsink'">
259                                <xsl:apply-templates select="$nestedDoc//*[PartID=$debbComponentId]" mode="heatsink">
260                                        <xsl:with-param name="instanceRefs" select="@id" />             
261                                </xsl:apply-templates>
262                        </xsl:if>
263                </xsl:if>
264        </xsl:template>
265       
266        <xsl:template match="plm:ProductRevisionView" mode="createTemplates">
267
268                <!-- instanceRefs contain space separated ids of nested DEBBs -->
269                <xsl:variable name="tokenizedText" select="tokenize(@instanceRefs, ' ')" />
270       
271                <xsl:variable name="debbLevel"
272                        select="plm:UserData/plm:UserValue[@title='DEBBLevel']/@value" />
273                       
274                <xsl:variable name="debbComponentId"
275                        select="plm:UserData/plm:UserValue[@title='DEBBComponentId']/@value" />
276
277                <xsl:variable name="debbComponentFile"
278                        select="plm:UserData/plm:UserValue[@title='DEBBComponentFile']/@value" />
279
280       
281                <xsl:if test="$debbLevel">
282                        <xsl:element name="computingResourceTemplate">
283                                <xsl:attribute name="name">
284                                        <xsl:value-of select="$debbLevel"/>
285                                        <xsl:text>-</xsl:text>
286                                        <xsl:value-of select="$debbComponentId"/>
287                                </xsl:attribute>
288                                <xsl:attribute name="class">
289                                        <xsl:value-of select="$debbLevel"/>
290                                </xsl:attribute>
291                               
292                                <!-- Read information from DEBBComponent file -->       
293                                <xsl:choose>
294                                         <!-- DEBB Components file is defined  -->
295                                        <xsl:when test="$debbComponentFile != ''">
296                                                <xsl:variable name="nestedDoc" select="document($debbComponentFile)" />
297
298                                                <xsl:apply-templates select="$nestedDoc//*[PartID=$debbComponentId]" mode="component">
299                                                        <xsl:with-param name="instanceRefs" select="@instanceRefs" />                                                   
300                                                </xsl:apply-templates>
301                                       
302                                        </xsl:when>
303
304                                </xsl:choose>
305                               
306                                <!-- Iterate children and ask them to translate themselves -->
307                                <xsl:for-each select="1 to count($tokenizedText)">
308                                        <xsl:variable name="index" select="." />
309                                        <xsl:apply-templates
310                                                select="$rootDoc//plm:ProductInstance[@id=$tokenizedText[$index]]" mode="createHierarchy"/>
311                                </xsl:for-each>                 
312                                                       
313                        </xsl:element>
314                </xsl:if>
315        </xsl:template>
316       
317        <xsl:template match="plm:ProductInstance" mode="updateHeatsinkDevice">
318
319                <xsl:variable name="power-sensor"
320                        select="plm:UserData/plm:UserValue[@title='power-sensor']/@value" />
321                <xsl:choose>
322                <xsl:when test="$power-sensor != ''">
323                                <xsl:element name="parameter">
324                                        <xsl:attribute name="name">power-sensor</xsl:attribute>
325                                        <xsl:element name="value">
326                                                <xsl:value-of select="$power-sensor" />
327                                        </xsl:element>
328                                </xsl:element>
329                        </xsl:when>
330                        <xsl:otherwise>
331                                <xsl:element name="parameter">
332                                        <xsl:attribute name="name">power-sensor</xsl:attribute>
333                                        <xsl:element name="value">power</xsl:element>
334                                </xsl:element>
335                        </xsl:otherwise>
336                </xsl:choose>
337       
338                <!--
339                <xsl:variable name="temperature-sensor"
340                        select="plm:UserData/plm:UserValue[@title='temperature-sensor']/@value" />
341                <xsl:choose>
342                        <xsl:when test="$temperature-sensor != ''">
343                                <xsl:element name="parameter">
344                                        <xsl:attribute name="name">temperature-sensor</xsl:attribute>
345                                        <xsl:element name="value">
346                                                <xsl:value-of select="$temperature-sensor" />
347                                        </xsl:element>
348                                </xsl:element>
349                        </xsl:when>
350                        <xsl:otherwise>
351                                <xsl:element name="parameter">
352                                        <xsl:attribute name="name">temperature-sensor</xsl:attribute>
353                                        <xsl:element name="value">temperature</xsl:element>
354                                </xsl:element>
355                        </xsl:otherwise>
356                </xsl:choose>
357                -->
358        </xsl:template>
359       
360        <xsl:template match="plm:ProductInstance" mode="updateCoolingDevice">
361
362                <xsl:variable name="airflow_volume-sensor"
363                        select="plm:UserData/plm:UserValue[@title='airflow_volume-sensor']/@value" />
364                <xsl:choose>
365                        <xsl:when test="$airflow_volume-sensor != ''">
366                                <xsl:element name="parameter">
367                                        <xsl:attribute name="name">airflow_volume-sensor</xsl:attribute>
368                                        <xsl:element name="value">
369                                                <xsl:value-of select="$airflow_volume-sensor" />
370                                        </xsl:element>
371                                </xsl:element>
372                        </xsl:when>
373                        <xsl:otherwise>
374                                <xsl:element name="parameter">
375                                        <xsl:attribute name="name">airflow_volume-sensor</xsl:attribute>
376                                        <xsl:element name="value">airflow_volume</xsl:element>
377                                </xsl:element>
378                        </xsl:otherwise>
379                </xsl:choose>
380               
381                <xsl:variable name="airflow_speed-sensor"
382                        select="plm:UserData/plm:UserValue[@title='airflow_speed-sensor']/@value" />
383                <xsl:choose>   
384                        <xsl:when test="$airflow_speed-sensor != ''">
385                                <xsl:element name="parameter">
386                                        <xsl:attribute name="name">airflow_speed-sensor</xsl:attribute>
387                                        <xsl:element name="value">
388                                                <xsl:value-of select="$airflow_speed-sensor" />
389                                        </xsl:element>
390                                </xsl:element>
391                        </xsl:when>
392                        <xsl:otherwise>
393                                <xsl:element name="parameter">
394                                        <xsl:attribute name="name">airflow_speed-sensor</xsl:attribute>
395                                        <xsl:element name="value">airflow_speed</xsl:element>
396                                </xsl:element>
397                        </xsl:otherwise>
398                </xsl:choose>
399
400                <xsl:variable name="temperature-sensor"
401                        select="plm:UserData/plm:UserValue[@title='temperature-sensor']/@value" />
402                <xsl:choose>
403                        <xsl:when test="$temperature-sensor != ''">
404                                <xsl:element name="parameter">
405                                        <xsl:attribute name="name">temperature-sensor</xsl:attribute>
406                                        <xsl:element name="value">
407                                                <xsl:value-of select="$temperature-sensor" />
408                                        </xsl:element>
409                                </xsl:element>
410                        </xsl:when>
411                        <xsl:otherwise>
412                                <xsl:element name="parameter">
413                                        <xsl:attribute name="name">temperature-sensor</xsl:attribute>
414                                        <xsl:element name="value">temperature</xsl:element>
415                                </xsl:element>
416                        </xsl:otherwise>
417                </xsl:choose>
418        </xsl:template>
419       
420        <xsl:function name="fun:containsTemplates">
421                <xsl:variable name="productRevisionViews" select="$rootDoc//plm:ProductRevisionView[plm:UserData/plm:UserValue/@title='DEBBLevel' and plm:UserData/plm:UserValue/@value=$templateStartLevel]"/>
422                <xsl:variable name="numberOfTemplates" select="count($productRevisionViews)"/>
423
424                <xsl:value-of select="$numberOfTemplates &gt; 0"/>
425        </xsl:function>
426       
427</xsl:stylesheet>
428
Note: See TracBrowser for help on using the repository browser.