OASIS Universal Business Language (UBL) TC

 View Only

Transforming Global NDR Schemas to Local NDR Schemas

  • 1.  Transforming Global NDR Schemas to Local NDR Schemas

    Posted 06-14-2005 13:42
     MHonArc v2.5.0b2 -->
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    ubl message

    [Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]


    Subject: Transforming Global NDR Schemas to Local NDR Schemas


    Greetings
     
    I've been looking a little (unofficially) at how
    feasible it might be to transform UBL-NDR-type
    (global) schemas into local NDR-type
    schemas using XSLT (2.0)
     
    An hour or so of work produced the attached
    illustrative prototypes, summarized below.
     
    Note - the concept may be far *less simple* for
    the minor version schemas - here I've only
    been looking at major version schemas without
    the polymorphism envisioned for the global NDR
     
    Note too: I've only tried writing a stylesheet for
    the document schemas, I've started with a
    module design which is similar for both sets of
    schemas and I've kept the schemas very simple,
    ignoring annotation/documentation.
     
    I get the impression though that the whole idea
    is rather feasible, given adequate resources/time.
     
    All the best
     
    Steve
     
     
     
    Transforming Global NDR Schemas to Local NDR Schemas
    (major versions)
     
    Stephen Green
    June 2005
     

    Exclusions from this concept illustration:
     
    Transformations for the imported schemas
    Transformations of Annotation/Documentation in Schemas
    Transformations of Comments in Schemas
    ** Minor version schemas **
     
     
     
    Example of Global NDR:
     
    Document Schema -
     
    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns="SomeDocument"
        xmlns:uac2-0="GlobalImportedAggregateSchema"
        xmlns:ubc2-0="GlobalImportedBasicSchema"
        targetNamespace="SomeDocument"
        elementFormDefault="qualified"
        attributeFormDefault="unqualified"
        version="1.0">
      <xsd:import namespace="GlobalImportedAggregateSchema" schemaLocation="GlobalImportedAggregateSchema.xsd"/>
      <xsd:import namespace="GlobalImportedBasicSchema" schemaLocation="GlobalImportedBasicSchema.xsd"/>
      <xsd:element name="SomeDocument" type="SomeDocumentType">
        <xsd:annotation>
          <xsd:documentation>Some documentation</xsd:documentation>
        </xsd:annotation>
      </xsd:element>
      <xsd:complexType name="SomeDocumentType">
        <xsd:annotation>
          <xsd:documentation>Some documentation</xsd:documentation>
        </xsd:annotation>
        <xsd:sequence>
          <xsd:element ref="Something" minOccurs="0" maxOccurs="1">
            <xsd:annotation>
              <xsd:documentation>Some documentation</xsd:documentation>
            </xsd:annotation>
          </xsd:element>
        </xsd:sequence>
      </xsd:complexType>
      <xsd:element name="Something" type="uac2-0:SomethingType"/>
    </xsd:schema>
     

    Example Document -
     
    <?xml version="1.0" encoding="UTF-8"?>
    <SomeDocument xmlns:AIAS="LocalImportedAggregateSchema" xmlns:AIBS="LocalImportedBasicSchema" xmlns="SomeDocument" xmlns:uac2-0="GlobalImportedAggregateSchema" xmlns:ubc2-0="GlobalImportedBasicSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="SomeDocument
    GlobalDocumentSchema.xsd">
     <Something>
      <uac2-0:SomeReference>
       <ubc2-0:SomeID ID="String">normalizedString</ubc2-0:SomeID>
      </uac2-0:SomeReference>
     </Something>
    </SomeDocument>
     

    Example of Local NDR:
     
    Document Schema -
     
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns="SomeDocument" xmlns:AIAS="LocalImportedAggregateSchema" xmlns:AIBS="LocalImportedBasicSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="SomeDocument" elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.0">
     <xs:import namespace="LocalImportedAggregateSchema" schemaLocation="LocalImportedAggregateSchema.xsd"/>
     <xs:import namespace="LocalImportedBasicSchema" schemaLocation="LocalImportedBasicSchema.xsd"/>
     <xs:element name="SomeDocument" type="SomeDocumentType"/>
     <xs:complexType name="SomeDocumentType">
      <xs:sequence>
       <xs:element name="Something" type="AIAS:SomethingType" minOccurs="0"/>
      </xs:sequence>
     </xs:complexType>
    </xs:schema>
     
    Example Document -
     
    <?xml version="1.0" encoding="UTF-8"?>
    <SomeDocument xmlns:AIAS="LocalImportedAggregateSchema" xmlns:AIBS="LocalImportedBasicSchema" xmlns="SomeDocument" xmlns:uac2-0="GlobalImportedAggregateSchema" xmlns:ubc2-0="GlobalImportedBasicSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="SomeDocument
    LocalDocumentSchema.xsd">
     <Something>
      <AIAS:SomeReference>
       <AIBS:SomeID ID="String">normalizedString</AIBS:SomeID>
      </AIAS:SomeReference>
     </Something>
    </SomeDocument>
     
     
     

    Sample Stylesheet (for the transformation of the document schemas):
     

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fn="http://www.w3.org/2005/02/xpath-functions" xmlns:xdt="http://www.w3.org/2005/02/xpath-datatypes" xmlns:ubc2-0="GlobalImportedBasicSchema" xmlns:uac2-0="GlobalImportedAggregateSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="uac2-0 ubc2-0 xsd fn xdt" >
     <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
     <xsl:template match="/">
      <xsl:for-each select="xsd:schema">
       <xs:schema xmlns:AIBS="LocalImportedBasicSchema" xmlns:AIAS="LocalImportedAggregateSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="SomeDocument">
        <xsl:attribute name="targetNamespace"><xsl:value-of select="@targetNamespace"/></xsl:attribute>
        <xsl:attribute name="elementFormDefault"><xsl:value-of select="@elementFormDefault"/></xsl:attribute>
        <xsl:attribute name="attributeFormDefault"><xsl:value-of select="@attributeFormDefault"/></xsl:attribute>
        <xsl:attribute name="version"><xsl:value-of select="@version"/></xsl:attribute>
        <xs:import>
         <xsl:attribute name="namespace">LocalImportedAggregateSchema</xsl:attribute>
         <xsl:attribute name="schemaLocation">LocalImportedAggregateSchema.xsd</xsl:attribute>
        </xs:import>
        <xs:import>
         <xsl:attribute name="namespace">LocalImportedBasicSchema</xsl:attribute>
         <xsl:attribute name="schemaLocation">LocalImportedBasicSchema.xsd</xsl:attribute>
        </xs:import>
        <xsl:for-each select="xsd:element[1]">
         <xs:element>
          <xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>
          <xsl:attribute name="type"><xsl:value-of select="@type"/></xsl:attribute>
         </xs:element>
        </xsl:for-each>
        <!-- xsd:element[>1] could be used (with XSLT 2.0 say) to contribute to the imported schema content -->
        <xsl:for-each select="xsd:complexType">
         <xs:complexType>
          <xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>
          <xs:sequence>
           <xsl:for-each select="xsd:sequence/xsd:element">
            <xs:element>
             <xsl:attribute name="name"><xsl:value-of select="@ref"/></xsl:attribute>
             <xsl:attribute name="type"><xsl:value-of select="concat('AIAS:', @ref, 'Type')"/></xsl:attribute>
             <xsl:attribute name="minOccurs"><xsl:value-of select="@minOccurs"/></xsl:attribute>
            </xs:element>
           </xsl:for-each>
          </xs:sequence>
         </xs:complexType>
        </xsl:for-each>
       </xs:schema>
      </xsl:for-each>
     </xsl:template>
    </xsl:stylesheet>
     
     
     
    Imported Schemas:
     

    Global NDR Imported Aggregate Schema -
     
    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="GlobalImportedAggregateSchema" xmlns:ubc2-0="GlobalImportedBasicSchema" targetNamespace="GlobalImportedAggregateSchema" elementFormDefault="qualified" attributeFormDefault="unqualified" version="test">
     <xsd:import namespace="GlobalImportedBasicSchema" schemaLocation="GlobalImportedBasicSchema.xsd"/>
     <xsd:element name="Something" type="SomethingType"/>
     <xsd:element name="SomeReference" type="SomeReferenceType"/>
     <xsd:complexType name="SomethingType">
      <xsd:sequence>
       <xsd:element ref="SomeReference" minOccurs="0"/>
      </xsd:sequence>
     </xsd:complexType>
     <xsd:complexType name="SomeReferenceType">
      <xsd:sequence>
       <xsd:element ref="ubc2-0:SomeID" minOccurs="0"/>
      </xsd:sequence>
     </xsd:complexType>
    </xsd:schema>
     
    Global NDR Imported Basic Schema -
     
    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="GlobalImportedBasicSchema" xmlns:udt="SchemaModule" targetNamespace="GlobalImportedBasicSchema" elementFormDefault="qualified" attributeFormDefault="unqualified" version="test">
     <xsd:import namespace="SchemaModule" schemaLocation="UnqualifiedDataType.xsd"/>
     <xsd:element name="SomeID" type="IdentifierType"/>
     <xsd:complexType name="IdentifierType">
      <xsd:simpleContent>
       <xsd:extension base="udt:IdentifierType"/>
      </xsd:simpleContent>
     </xsd:complexType>
    </xsd:schema>
     

    Common Datatypes Schema ('Unqualified') -
     
    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema targetNamespace="SchemaModule" xmlns:udt="SchemaModule" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xsd:complexType name="IdentifierType">
      <xsd:simpleContent>
       <xsd:extension base="xsd:normalizedString">
        <xsd:attribute name="ID" type="xsd:normalizedString" use="optional">
        </xsd:attribute>
       </xsd:extension>
      </xsd:simpleContent>
     </xsd:complexType>
    </xsd:schema>
     
    Local NDR Imported Aggregate Schema -
     
    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="LocalImportedAggregateSchema" xmlns:AIBS="LocalImportedBasicSchema" targetNamespace="LocalImportedAggregateSchema" elementFormDefault="qualified" attributeFormDefault="unqualified" version="test">
     <xsd:import namespace="LocalImportedBasicSchema" schemaLocation="LocalImportedBasicSchema.xsd"/>
     <xsd:complexType name="SomethingType">
      <xsd:sequence>
       <xsd:element name="SomeReference" type="AIBS:SomeReferenceType" minOccurs="0"/>
      </xsd:sequence>
     </xsd:complexType>
    </xsd:schema>
     

    Local NDR Imported Basic Schema -
     
    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="LocalImportedBasicSchema" xmlns:udt="SchemaModule" targetNamespace="LocalImportedBasicSchema" elementFormDefault="qualified" attributeFormDefault="unqualified" version="test">
     <xsd:import namespace="SchemaModule" schemaLocation="UnqualifiedDataType.xsd"/>
     <xsd:complexType name="SomeReferenceType">
      <xsd:sequence>
       <xsd:element name="SomeID" type="udt:IdentifierType"/>
      </xsd:sequence>
     </xsd:complexType>
    </xsd:schema>
     
     
     
     
     
     
     
     

    GlobalLocalSchemaTransformation.zzz



    [Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]