<?xml version="1.0" encoding="utf-16"?>
<xsl:stylesheet version="1.0" xmlns="http://www.plmx.org/2007/10/PLMX" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"  >
  <xsl:output method="xml" indent="yes"/>
  <xsl:template match="/">
    <plmx>
      <xsl:apply-templates select="NewDataSet"/>
    </plmx>
  </xsl:template>
  <xsl:template name="ds" match="NewDataSet">
    <part id="FCC65F4E-583E-47a4-8A20-93AC67BA8381">
      <structureItems>
        <xsl:for-each select="child::node()">
          <xsl:call-template name="structureItem"/>
        </xsl:for-each>
      </structureItems>
    </part>
  </xsl:template>
  <xsl:template match="Owner_x0020_Name">
    <name >
      <xsl:value-of select="."/>
    </name>
  </xsl:template>
  <xsl:template match="Type_x0020_Name">
    <name >
      <xsl:value-of select="."/>
    </name>
  </xsl:template>
  <xsl:template match="Type_x0020_Abbreviation">
    <abbreviation >
      <xsl:value-of select="."/>
    </abbreviation>
  </xsl:template>
  <xsl:template match="Number">
    <identifier>
      <xsl:value-of select="."/>
    </identifier>
  </xsl:template>
  <xsl:template match="Reference">
    <referenceDesignators>
      <referenceDesignator>
        <xsl:value-of select="."/>
      </referenceDesignator>
    </referenceDesignators>
  </xsl:template>
  <xsl:template match="Unit">
    <unitOfMeasure>
      <name>
        <xsl:value-of select="."/>
      </name>
    </unitOfMeasure>
  </xsl:template>

  <xsl:template  name ="structureItem">
    <xsl:if test="Item!=''">
      <structureItem>
        <findNumber>
          <xsl:value-of select="Item"/>
        </findNumber>
        <xsl:choose>
          <xsl:when test="Class='Document'">
            <document>
              <owner>
                <xsl:apply-templates select="Owner_x0020_Name"/>
              </owner>
              <xsl:apply-templates select="Number"/>
              <type>
                <xsl:apply-templates select="Type_x0020_Name"/>
                <xsl:apply-templates select ="Type_x0020_Abbreviation"/>
              </type>
            </document>
          </xsl:when>
          <xsl:otherwise>
            <part>
              <owner>
                <xsl:apply-templates select="Owner_x0020_Name"/>
              </owner>
              <xsl:apply-templates select="Number"/>
              <type>
                <xsl:apply-templates select="Type_x0020_Name"/>
                <xsl:apply-templates select ="Type_x0020_Abbreviation"/>
              </type>
            </part>
            <quantity>
              <xsl:apply-templates select="Unit"/>
              <value>
                <xsl:value-of  select="Quantity"/>
              </value>
            </quantity>
            <xsl:apply-templates select="Reference"/>
          </xsl:otherwise>
        </xsl:choose>
      </structureItem>
    </xsl:if>
  </xsl:template>
</xsl:stylesheet>