Ignore:
Timestamp:
03/12/13 12:37:06 (12 years ago)
Author:
gosiaw
Message:

Templates for all types of computing devices added

File:
1 edited

Legend:

Unmodified
Added
Removed
  • DCWoRMS/branches/coolemall/src/test/DEBBTranslator/xml/PLMXMLTranslator.xsl

    r941 r946  
    11<?xml version="1.0" encoding="UTF-8"?> 
    2 <xsl:stylesheet version="1.0" 
     2<xsl:stylesheet version="2.0" 
    33        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"> 
     4        xmlns:cim="http://www.coolemall.eu/DEBBComponent" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     5        xmlns:fun="http://whatever"> 
    56 
    67        <!-- Importing xslt for translating debb components --> 
     
    3233                        <xsl:attribute name="xsi:noNamespaceSchemaLocation">DCWormsResSchema.xsd</xsl:attribute> 
    3334                        <xsl:element name="resources"> 
    34                                 <xsl:apply-templates select="//plm:InstanceGraph" /> 
     35                                <!-- Iterate the document, create hierarchy and "links" to templates --> 
     36                                <xsl:apply-templates select="//plm:InstanceGraph" mode="createHierarchy"/> 
     37                                                                 
     38                                <!-- Create main scheduler --> 
    3539                                <xsl:element name="scheduler"></xsl:element> 
    3640                        </xsl:element> 
     41                         
     42                        <xsl:element name="templates"> 
     43                                <!-- Iterate the document and createTemplates --> 
     44                                <xsl:apply-templates select="//plm:InstanceGraph" mode="createTemplates"/> 
     45                        </xsl:element> 
     46                         
    3747                </xsl:element> 
    3848        </xsl:template> 
    3949 
    40         <xsl:template match="plm:InstanceGraph"> 
     50        <xsl:template match="plm:InstanceGraph" mode="createHierarchy"> 
    4151                <!-- Finding root DEBB --> 
    4252                <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"> 
     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:apply-templates select="plm:ProductRevisionView" mode="createTemplates"/> 
     58        </xsl:template> 
     59 
     60        <xsl:template match="plm:ProductInstance" mode="createHierarchy"> 
    4761                <xsl:variable name="partRef" select="@partRef" /> 
    4862                <!-- Get rid of # at the beginning --> 
     
    5468                                <xsl:attribute name="name"><xsl:value-of select="@name" /></xsl:attribute> 
    5569 
    56                                 <!-- Find corresponding ProductRevisionView and let it translate itself --> 
    57                                 <xsl:apply-templates 
    58                                         select="//plm:ProductRevisionView[@id=$productInstanceId]" /> 
    5970 
    6071                                <!-- Add hostnames, labels, locations, sequences, etc. --> 
     
    99110                                        </xsl:element> 
    100111                                </xsl:if> 
     112                                 
     113                                <!-- Find corresponding ProductRevisionView and let it translate itself --> 
     114<!--                            <xsl:apply-templates--> 
     115<!--                                    select="//plm:ProductRevisionView[@id=$productInstanceId]" />--> 
     116                                <xsl:apply-templates select="//plm:ProductRevisionView[@id=$productInstanceId]" mode="createHierarchy"/> 
     117                                 
     118                                 
    101119                        </xsl:element> 
    102120                </xsl:if> 
    103121        </xsl:template> 
    104  
    105         <xsl:template match="plm:ProductRevisionView"> 
     122         
     123         
     124        <xsl:template match="plm:ProductRevisionView" mode="createHierarchy"> 
     125 
    106126                <!-- instanceRefs contain space separated ids of nested DEBBs --> 
    107127                <xsl:variable name="tokenizedText" select="tokenize(@instanceRefs, ' ')" /> 
    108  
     128         
    109129                <!-- DEBBLevel --> 
    110130                <xsl:variable name="debbLevel" 
     
    113133                <xsl:variable name="debbComponentId" 
    114134                        select="plm:UserData/plm:UserValue[@title='DEBBComponentId']/@value" /> 
    115                 <!-- DEBBComponentFile --> 
     135         
     136                <xsl:element name="templateId"> 
     137                        <xsl:value-of select="$debbLevel"/> 
     138                        <xsl:text>-</xsl:text> 
     139                        <xsl:value-of select="$debbComponentId"/> 
     140                </xsl:element> 
     141 
     142                <!-- Iterate children and ask them to translate themselves --> 
     143                <xsl:for-each select="1 to count($tokenizedText)"> 
     144                        <xsl:variable name="index" select="." /> 
     145                        <xsl:apply-templates 
     146                                select="$rootDoc//plm:ProductInstance[@id=$tokenizedText[$index]]" mode="createHierarchy"/> 
     147                </xsl:for-each> 
     148                 
     149        </xsl:template> 
     150         
     151        <xsl:template match="plm:ProductRevisionView" mode="createTemplates"> 
     152         
     153                <xsl:variable name="debbLevel" 
     154                        select="plm:UserData/plm:UserValue[@title='DEBBLevel']/@value" /> 
     155                         
     156                <xsl:variable name="debbComponentId" 
     157                        select="plm:UserData/plm:UserValue[@title='DEBBComponentId']/@value" /> 
     158 
     159                <xsl:variable name="debbComponentFile" 
     160                        select="plm:UserData/plm:UserValue[@title='DEBBComponentFile']/@value" /> 
     161         
     162                <xsl:if test="$debbLevel"> 
     163                        <xsl:element name="computingResourceTemplate"> 
     164                                <xsl:attribute name="name"> 
     165                                        <xsl:value-of select="$debbLevel"/> 
     166                                        <xsl:text>-</xsl:text> 
     167                                        <xsl:value-of select="$debbComponentId"/> 
     168                                </xsl:attribute> 
     169                                <xsl:attribute name="class"> 
     170                                        <xsl:value-of select="$debbLevel"/> 
     171                                </xsl:attribute> 
     172                                 
     173                                <!-- Read information from DEBBComponent file --> 
     174                 
     175                                <xsl:choose> 
     176                                         <!-- DEBB Components file is defined  --> 
     177                                        <xsl:when test="$debbComponentFile != ''"> 
     178                                                <xsl:comment> 
     179                                                        DEBB Component file is <xsl:value-of select="$debbComponentFile" /> 
     180                                                </xsl:comment> 
     181                                                <xsl:variable name="nestedDoc" select="document($debbComponentFile)" /> 
     182                                         
     183<!--                                            <xsl:value-of select="fun:translateDEBBComponent($nestedDoc, $debbComponentFile)"/>--> 
     184 
     185                                                <xsl:apply-templates select="$nestedDoc//*[ComponentId=$debbComponentId]"> 
     186                                                        <xsl:with-param name="computingResourceClasses"> 
     187                                                                <xsl:value-of select="$computingResourceClasses" /> 
     188                                                        </xsl:with-param> 
     189                                                        <xsl:with-param name="resourceUnitClasses"> 
     190                                                                <xsl:value-of select="$resourceUnitClasses" /> 
     191                                                        </xsl:with-param> 
     192                                                </xsl:apply-templates> 
     193                                         
     194                                        </xsl:when> 
     195                                         <!-- DEBB Components file is not defined. Use default one.  --> 
     196                                        <xsl:otherwise> 
     197                                                <xsl:comment> 
     198                                                        DEBB Component file is <xsl:value-of select="$defaultDEBBComponentsFileName" /> 
     199                                                </xsl:comment> 
     200                                                <xsl:variable name="nestedDoc" 
     201                                                        select="document($defaultDEBBComponentsFileName)" /> 
     202                 
     203<!--                                                    <xsl:value-of select="fun:translateDEBBComponent($nestedDoc, $debbComponentFile)"/>--> 
     204                                                         
     205                                                <xsl:apply-templates select="$nestedDoc//*[ComponentId=$debbComponentId]"> 
     206                                                        <xsl:with-param name="computingResourceClasses"> 
     207                                                                <xsl:value-of select="$computingResourceClasses" /> 
     208                                                        </xsl:with-param> 
     209                                                        <xsl:with-param name="resourceUnitClasses"> 
     210                                                                <xsl:value-of select="$resourceUnitClasses" /> 
     211                                                        </xsl:with-param> 
     212                                                </xsl:apply-templates> 
     213                 
     214                                        </xsl:otherwise> 
     215                                </xsl:choose>                    
     216                        </xsl:element> 
     217                </xsl:if> 
     218        </xsl:template> 
     219         
     220        <xsl:function name="fun:translateDEBBComponent"> 
     221                <xsl:param name="nestedDoc"/> 
     222                <xsl:param name="debbComponentId"/> 
     223         
     224                <xsl:text>BEGIN</xsl:text> 
     225                debbComponentId=<xsl:value-of select="$debbComponentId"/> 
     226                <xsl:comment> 
     227                        <xsl:text>translateDEBBComponent(</xsl:text> 
     228                        <xsl:value-of select="$nestedDoc/ComponentId"/> 
     229                        <xsl:text>, </xsl:text> 
     230                        <xsl:value-of select="$debbComponentId"/> 
     231                        <xsl:text>)</xsl:text> 
     232                </xsl:comment> 
     233                 
     234                <!-- Does not work :((( --> 
     235                <xsl:apply-templates select="$nestedDoc//*[ComponentId=$debbComponentId]"> 
     236                        <xsl:with-param name="computingResourceClasses"> 
     237                                <xsl:value-of select="$computingResourceClasses" /> 
     238                        </xsl:with-param> 
     239                        <xsl:with-param name="resourceUnitClasses"> 
     240                                <xsl:value-of select="$resourceUnitClasses" /> 
     241                        </xsl:with-param> 
     242                </xsl:apply-templates> 
     243 
     244                <xsl:text>END</xsl:text> 
     245         
     246         
     247        </xsl:function> 
     248         
     249        <!-- 
     250         
     251        <xsl:template match="plm:ProductRevisionView" mode="createTemplates"> 
     252                 
     253                 instanceRefs contain space separated ids of nested DEBBs  
     254                <xsl:variable name="tokenizedText" select="tokenize(@instanceRefs, ' ')" /> 
     255                 
     256                 DEBBLevel  
     257                <xsl:variable name="debbLevel" 
     258                        select="plm:UserData/plm:UserValue[@title='DEBBLevel']/@value" /> 
     259                 DEBBComponentId  
     260                <xsl:variable name="debbComponentId" 
     261                        select="plm:UserData/plm:UserValue[@title='DEBBComponentId']/@value" /> 
     262                 DEBBComponentFile  
    116263                <xsl:variable name="debbComponentFile" 
    117264                        select="plm:UserData/plm:UserValue[@title='DEBBComponentFile']/@value" /> 
     
    127274                </xsl:if> 
    128275 
    129                 <!-- Add DEBB information from DEBB Components file --> 
     276                 
     277                 Add DEBB information from DEBB Components file  
     278                <xsl:attribute name="test">choose</xsl:attribute> 
    130279                <xsl:choose> 
    131                         <!-- DEBB Components file is defined --> 
     280                         DEBB Components file is defined  
    132281                        <xsl:when test="$debbComponentFile != ''"> 
    133282                                <xsl:comment> 
     
    137286                                <xsl:variable name="nestedDoc" select="document($debbComponentFile)" /> 
    138287                                <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)" /> 
     288 
    148289                                <xsl:apply-templates select="$nestedDoc//*[ComponentId=$debbComponentId]"> 
    149290                                        <xsl:with-param name="computingResourceClasses"> 
     
    154295                                        </xsl:with-param> 
    155296                                </xsl:apply-templates> 
     297                         
     298                                <xsl:call-template name="translateDEBBComponent"> 
     299                                        <xsl:with-param name="nestedDoc"><xsl:value-of select="$nestedDoc"/></xsl:with-param> 
     300                                        <xsl:with-param name="debbComponentId"><xsl:value-of select="$debbComponentId"/></xsl:with-param> 
     301                                </xsl:call-template> 
     302                        </xsl:when> 
     303                         DEBB Components file is not defined. Use default one.  
     304                        <xsl:otherwise> 
     305                                <xsl:comment> 
     306                                        DEBB Component file is 
     307                                        <xsl:value-of select="$defaultDEBBComponentsFileName" /> 
     308                                </xsl:comment> 
     309                                <xsl:variable name="nestedDoc" 
     310                                        select="document($defaultDEBBComponentsFileName)" /> 
     311 
     312 
     313                                <xsl:call-template name="translateDEBBComponent"> 
     314                                        <xsl:with-param name="nestedDoc"><xsl:value-of select="$nestedDoc"/></xsl:with-param> 
     315                                        <xsl:with-param name="debbComponentId"><xsl:value-of select="$debbComponentId"/></xsl:with-param> 
     316                                </xsl:call-template> 
     317                                         
     318                                <xsl:apply-templates select="$nestedDoc//*[ComponentId=$debbComponentId]"> 
     319                                        <xsl:with-param name="computingResourceClasses"> 
     320                                                <xsl:value-of select="$computingResourceClasses" /> 
     321                                        </xsl:with-param> 
     322                                        <xsl:with-param name="resourceUnitClasses"> 
     323                                                <xsl:value-of select="$resourceUnitClasses" /> 
     324                                        </xsl:with-param> 
     325                                </xsl:apply-templates> 
     326                                         
    156327                        </xsl:otherwise> 
    157328                </xsl:choose> 
    158  
    159                 <!-- Iterate children and ask them to translate themselves --> 
     329                 
     330                 
     331 
     332                 Iterate children and ask them to translate themselves  
    160333                <xsl:for-each select="1 to count($tokenizedText)"> 
    161334                        <xsl:variable name="index" select="." /> 
     
    164337                </xsl:for-each> 
    165338        </xsl:template> 
     339         
     340        --> 
     341                 
     342         
     343         
    166344</xsl:stylesheet> 
    167345 
Note: See TracChangeset for help on using the changeset viewer.