dd2tree.xsl 5.42 KB
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml"/>
 
<xsl:template match="dataRoot/dataCenter">
<dataRoot>
 <dataCenter name="AMDA" desc="AMDA_Internal_Data_Base" xml:id="myLocalData-treeRootNode">
  <xsl:for-each select="mission">
    <mission att="{@attention}" name="{@name}" rank="{@rank}" xml:id="{@name}" desc="{@desc}" target="{target}" available="{@available}">            
        <xsl:choose>
                <xsl:when test="group">
                    <xsl:for-each select="group">
                       <group att="{@attention}" name="{@name}" xml:id="{@xml:id}" desc="{@desc}" restricted="{@restricted}">
                            <xsl:for-each select="instrument">
                                <instrument att="{@attention}" name="{@name}" xml:id="{@xml:id}" desc="{@desc}" restricted="{@restricted}">           
                                    <xsl:for-each select="dataset">
                                        <xsl:apply-templates select="."/>
                                    </xsl:for-each>
                                </instrument> 
                            </xsl:for-each>       
                        </group>
                    </xsl:for-each>
                </xsl:when>
                <xsl:when test="simulationModel">
                    <xsl:for-each select="simulationModel">
                       <simulationModel att="{@attention}" name="{@name}" xml:id="{@xml:id}" desc="{@desc}" restricted="{@restricted}">
                            <xsl:for-each select="instrument">
                                <instrument att="{@attention}" name="{@name}" xml:id="{@xml:id}" desc="{@desc}" restricted="{@restricted}">           
                                    <xsl:for-each select="dataset">
                                        <xsl:apply-templates select="."/>
                                    </xsl:for-each>
                                </instrument> 
                            </xsl:for-each>       
                        </simulationModel>
                    </xsl:for-each>
                </xsl:when>
                <xsl:when test="observatory">
                    <xsl:for-each select="observatory">
                       <observatory att="{@attention}" name="{@name}" xml:id="{@xml:id}" desc="{@desc}" restricted="{@restricted}">
                            <xsl:for-each select="instrument">
                                <instrument att="{@attention}" name="{@name}" xml:id="{@xml:id}" desc="{@desc}">           
                                    <xsl:for-each select="dataset">
                                        <xsl:apply-templates select="."/>
                                    </xsl:for-each>
                                </instrument> 
                            </xsl:for-each>       
                        </observatory>
                    </xsl:for-each>
                </xsl:when>                                
                <xsl:otherwise>
                    <xsl:for-each select="instrument">
                        <instrument att="{@attention}" name="{@name}" xml:id="{parent::mission/@name}:{@name}" desc="{@desc}" restricted="{@restricted}">                                                                  
                                <xsl:for-each select="datasetGroup">
                                    <datasetGroup att="{@attention}" name="{@name}" xml:id="{@xml:id}" desc="{@desc}" restricted="{@restricted}">                                                                      
                                        <xsl:for-each select="dataset">
                                            <xsl:apply-templates select="."/>
                                        </xsl:for-each>
                                    </datasetGroup>
                                </xsl:for-each>                                                                                                   
                                <xsl:for-each select="dataset">
                                    <xsl:apply-templates select="."/>
                                </xsl:for-each>                            
                        </instrument>
                    </xsl:for-each> 
               </xsl:otherwise>  
        </xsl:choose>
     </mission>
   </xsl:for-each> 
  </dataCenter>
</dataRoot>
</xsl:template>

<xsl:template match="dataset">        
               <dataset att="{@attention}" restricted="{@restricted}" name="{@name}" xml:id="{@xml:id}" sampling="{sampling}" maxSampling="{maxSampling}" dataStart="{dataStart}" dataStop="{dataStop}" dataSource="{dataSource}" target="{target}">               
                 <xsl:for-each select="parameter"> 
                  <xsl:choose>
                    <xsl:when test="count(./child::*) &gt; 0 ">
                        <parameter name="{@name}" units="{@units}" display_type="{@display_type}" xml:id="{@xml:id}">                  
                        <xsl:for-each select="component">
                          <component name="{@name}" xml:id="{@xml:id}"/>
                        </xsl:for-each>
                      </parameter>
                   </xsl:when>
                  <xsl:otherwise>                     
                     <parameter name="{@name}" display_type="{@display_type}" units="{@units}" xml:id="{@xml:id}" />
                  </xsl:otherwise>
                </xsl:choose>
               </xsl:for-each> 
              </dataset>

</xsl:template>
</xsl:stylesheet>