source: DCWoRMS/trunk/src/test/DEBBTranslator/xml/PLMXMLTranslator.xsl @ 800

Revision 800, 6.1 KB checked in by gosiaw, 12 years ago (diff)

Checking if computingResource is not empty and adding this attribute in result file only if it is not empty

Line 
1<?xml version="1.0" encoding="UTF-8"?>
2<xsl:stylesheet version="1.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
6        <!-- Importing xslt for translating debb components -->
7        <xsl:import href="DEBBComponentTranslator.xsl" />
8
9        <!-- Information for mapping of DEBB classes into DCWoRMS computingResource
10                classes -->
11        <xsl:param name="computingResourceClasses" select="computingResourceClasses" />
12
13        <!-- Information for mapping of resource classes into DCWoRMS resourceUnits
14                classes -->
15        <!-- (Needed to pass to DEBB Components xslt) -->
16        <xsl:param name="resourceUnitClasses" select="resourceUnitClasses" />
17
18        <!-- Specification of the output document -->
19        <xsl:output method="xml" version="1.0" encoding="UTF-8"
20                indent="yes" />
21
22        <!-- Root of the PLM XML document -->
23        <xsl:variable name="rootDoc" select="/" />
24
25        <!-- Default DEBBComponents file name (used if it is not specified in PLM
26                XML file) -->
27        <xsl:variable name="defaultDEBBComponentsFileName" select="'DEBBComponents.xml'" />
28
29
30        <xsl:template match="/">
31                <xsl:element name="environment">
32                        <xsl:attribute name="xsi:noNamespaceSchemaLocation">DCWormsResSchema.xsd</xsl:attribute>
33                        <xsl:element name="resources">
34                                <xsl:apply-templates select="//plm:InstanceGraph" />
35                                <xsl:element name="scheduler"></xsl:element>
36                        </xsl:element>
37                </xsl:element>
38        </xsl:template>
39
40        <xsl:template match="plm:InstanceGraph">
41                <!-- Finding root DEBB -->
42                <xsl:variable name="rootRef" select="@rootRefs" />
43                <xsl:apply-templates select="plm:ProductInstance[@id=$rootRef]" />
44        </xsl:template>
45
46        <xsl:template match="plm:ProductInstance">
47                <xsl:variable name="partRef" select="@partRef" />
48                <!-- Get rid of # at the beginning -->
49                <xsl:variable name="productInstanceId" select="translate($partRef, '#', '')" />
50
51                <xsl:if test="not (starts-with(@name, 'Sensor'))">
52                        <!-- We have to get rid of sensors, which make only problems here -->
53                        <xsl:element name="computingResource">
54                                <xsl:attribute name="name"><xsl:value-of select="@name" /></xsl:attribute>
55
56                                <!-- Find corresponding ProductRevisionView and let it translate itself -->
57                                <xsl:apply-templates
58                                        select="//plm:ProductRevisionView[@id=$productInstanceId]" />
59
60                                <!-- Add hostnames, labels, locations, sequences, etc. -->
61                                <xsl:variable name="debbHostname"
62                                        select="plm:UserData/plm:UserValue[@title='hostname']/@value" />
63                                <xsl:if test="$debbHostname != ''">
64                                        <xsl:element name="parameter">
65                                                <xsl:attribute name="name">hostname</xsl:attribute>
66                                                <xsl:element name="value">
67                                                        <xsl:value-of select="$debbHostname" />
68                                                </xsl:element>
69                                        </xsl:element>
70                                </xsl:if>
71                                <xsl:variable name="debbLabel"
72                                        select="plm:UserData/plm:UserValue[@title='label']/@value" />
73                                <xsl:if test="$debbLabel != ''">
74                                        <xsl:element name="parameter">
75                                                <xsl:attribute name="name">label</xsl:attribute>
76                                                <xsl:element name="value">
77                                                        <xsl:value-of select="$debbLabel" />
78                                                </xsl:element>
79                                        </xsl:element>
80                                </xsl:if>
81                                <xsl:variable name="debbLocation"
82                                        select="plm:UserData/plm:UserValue[@title='location']/@value" />
83                                <xsl:if test="debbLocation != ''">
84                                        <xsl:element name="parameter">
85                                                <xsl:attribute name="name">location</xsl:attribute>
86                                                <xsl:element name="value">
87                                                        <xsl:value-of select="$debbLocation" />
88                                                </xsl:element>
89                                        </xsl:element>
90                                </xsl:if>
91                                <xsl:variable name="debbSequence"
92                                        select="plm:UserData/plm:UserValue[@title='sequence']/@value" />
93                                <xsl:if test="$debbSequence != ''">
94                                        <xsl:element name="parameter">
95                                                <xsl:attribute name="name">sequence</xsl:attribute>
96                                                <xsl:element name="value">
97                                                        <xsl:value-of select="$debbSequence" />
98                                                </xsl:element>
99                                        </xsl:element>
100                                </xsl:if>
101                        </xsl:element>
102                </xsl:if>
103        </xsl:template>
104
105        <xsl:template match="plm:ProductRevisionView">
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                <!-- DEBBComponentFile -->
116                <xsl:variable name="debbComponentFile"
117                        select="plm:UserData/plm:UserValue[@title='DEBBComponentFile']/@value" />
118
119                <xsl:attribute name="class">
120                        <xsl:value-of select="$debbLevel" />
121                </xsl:attribute>
122
123                <xsl:if test="$debbComponentId != ''">
124                        <xsl:attribute name="type">
125                                <xsl:value-of select="$debbComponentId" />
126                        </xsl:attribute>
127                </xsl:if>
128
129                <!-- Add DEBB information from DEBB Components file -->
130                <xsl:choose>
131                        <!-- DEBB Components file is defined -->
132                        <xsl:when test="$debbComponentFile != ''">
133                                <xsl:comment>
134                                        DEBB Component file is
135                                        <xsl:value-of select="$debbComponentFile" />
136                                </xsl:comment>
137                                <xsl:variable name="nestedDoc" select="document($debbComponentFile)" />
138                                <xsl:apply-templates select="$nestedDoc//*[ComponentId=$debbComponentId]" />
139                        </xsl:when>
140                        <!-- DEBB Components file is not defined. Use default one. -->
141                        <xsl:otherwise>
142                                <xsl:comment>
143                                        DEBB Component file is
144                                        <xsl:value-of select="$defaultDEBBComponentsFileName" />
145                                </xsl:comment>
146                                <xsl:variable name="nestedDoc"
147                                        select="document($defaultDEBBComponentsFileName)" />
148                                <xsl:apply-templates select="$nestedDoc//*[ComponentId=$debbComponentId]">
149                                        <xsl:with-param name="computingResourceClasses">
150                                                <xsl:value-of select="$computingResourceClasses" />
151                                        </xsl:with-param>
152                                        <xsl:with-param name="resourceUnitClasses">
153                                                <xsl:value-of select="$resourceUnitClasses" />
154                                        </xsl:with-param>
155                                </xsl:apply-templates>
156                        </xsl:otherwise>
157                </xsl:choose>
158
159                <!-- Iterate children and ask them to translate themselves -->
160                <xsl:for-each select="1 to count($tokenizedText)">
161                        <xsl:variable name="index" select="." />
162                        <xsl:apply-templates
163                                select="$rootDoc//plm:ProductInstance[@id=$tokenizedText[$index]]" />
164                </xsl:for-each>
165        </xsl:template>
166</xsl:stylesheet>
167
Note: See TracBrowser for help on using the repository browser.