<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  xmlns:plm="http://www.plmxml.org/Schemas/PLMXMLSchema"
  xmlns="http://www.plmxml.org/Schemas/PLMXMLSchema" exclude-result-prefixes="plm" >

<xsl:strip-space elements="*" />
<xsl:output method="xml" indent="yes"/>
<xsl:key name="datasetkey" match="/plm:PLMXML/plm:DataSet" use="@id"/>  

<!-- Main -->
<xsl:template match="*">
  <xsl:variable name="eleid" select="current()/@id"/>
  <xsl:variable name="elementName" select="name()"/>

  <xsl:choose>
    <xsl:when test="$elementName= 'ProductRevision'">
        <xsl:call-template name="writeProductRevision"/>
    </xsl:when>

	<xsl:when test="$elementName= 'AssociatedDataSet'">
	    <xsl:variable name="myId" select="/plm:PLMXML/plm:ProductRevision/plm:AssociatedDataSet/@id"/>
        <xsl:call-template name="writeAssociatedDataSet">
		<xsl:with-param name="Id" select="$eleid"/>
		<xsl:with-param name="MId" select="$myId"/>
		</xsl:call-template>
    </xsl:when>
    
    <xsl:when test="$elementName= 'PLMXML'">
        <xsl:call-template name="root-copy" />
    </xsl:when>
    <xsl:otherwise>
        <xsl:call-template name="copy-as-it-is" /> 
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<!-- Template to write the DataSet elements and to change type attribute values
-->
<xsl:template name="writeDataset">
  <xsl:call-template name="copy-as-it-is" />
</xsl:template>

<!-- Template to write AssociatedDataSet elements and to change the role
attribute values
-->
<xsl:template name="writeProductRevision">
    <xsl:call-template name="copy-as-it-is" /> 
	<AssociatedDataSet>
	</AssociatedDataSet>
</xsl:template>

<xsl:template name="writeAssociatedDataSet">
    <xsl:param name="Id"/>
	<xsl:param name="MId"/>
    <xsl:variable name="myId" select="/plm:PLMXML/plm:ProductRevision/plm:AssociatedDataSet/@id"/>
	<xsl:if test="$Id=$MId">
	        <xsl:call-template name="copy-as-it-is"/>
    </xsl:if>
</xsl:template>

<!-- Template to copy the element from source to target
-->
<xsl:template name="copy-as-it-is" >
  <xsl:element name="{name()}">
  <xsl:variable name="tempElementName" select="name()"/>
    <xsl:for-each select="@*">
      <xsl:attribute name="{name()}"><xsl:value-of select="."/></xsl:attribute>
    </xsl:for-each>
    <xsl:apply-templates />
  </xsl:element>
</xsl:template>

<xsl:template name="root-copy">
    <xsl:copy>
      <xsl:apply-templates />
    </xsl:copy>
</xsl:template>


</xsl:stylesheet>
<!-- Stylus Studio meta-information - (c) 2004-2005. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="000171_A.xml" userelativepaths="yes" externalpreview="no" url="000171_A.xml" htmlbaseurl="" outputurl="" processortype="internal" useresolver="yes" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator=""/></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no" ><SourceSchema srcSchemaPath="000171_A.xml" srcSchemaRoot="PLMXML" AssociatedInstance="" loaderFunction="document" loaderFunctionUsesURI="no"/></MapperInfo><MapperBlockPosition><template match="/"></template><template match="*"></template><template name="writeAssociatedDataSet"></template></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
-->