<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet 
    xmlns:upds="http://www.iris.edu/upds"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    <xsl:param name="prefix"/>
    <xsl:strip-space elements="*"/>
    <xsl:variable name="targetNS" select="/*/@targetNamespace"/>

    <xsl:template match="/xs:schema">
        <xsl:element name="UPDS_Config">
            <xsl:attribute name="xsi:schemaLocation">http://www.iris.edu/upds http://www.iris.edu/upds/schemas/upds_product_definition.xsd</xsl:attribute>
            <xsl:namespace name="cmt"  select="$targetNS"/>
            <xsl:apply-templates />
        </xsl:element>
    </xsl:template>
    
    <xsl:template match="xs:element[@substitutionGroup='upds:GenericProduct']">
        <xsl:element name="ProductRef">
            <xsl:attribute name="itemName" select="@type"/>
            <xsl:attribute name="namespaceUri" select="$targetNS"/>
        </xsl:element>
    </xsl:template>
    
    <xsl:template match="xs:complexType">
        <xsl:param name="xpath"/>
        <xsl:variable name="cTypeName" select="@name"/>
        <xsl:element name="ItemDef">
            <xsl:attribute name="name" select="$cTypeName"/>
            <xsl:attribute name="xpath" select="$xpath"/>
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>

