Providing an XML Transform (XSLT) to import XML data

XML can be imported into Koverse as any file can. To parse XML data into proper Koverse records, an XSLT must be used to convert XML into Koverse Record XML.

For example, let’s say you have the following XML file which you wish to import:

<?xml version="1.0" encoding="UTF-8"?>
<books xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
       xmlns='http://www.koverse/xml/example/books/1.0.0'>
  
  <book id="1">
    <author>Miguel De Cervantes</author>
    <title>Don Quixote</title>
  </book>
  
  <book id="2">
    <author>John Bunyan</author>
    <title>Pilgrim's Progress</title>
  </book>
  
  <book id="3">
    <author>Daniel Defoe</author>
    <title>Robinson Crusoe</title>
  </book>
  
</books>

For this example, this XML file would conform to your XML schema (XSD):

<?xml version="1.0"?>
<xs:schema version="1.0" elementFormDefault="qualified"
           xmlns:tns="http://www.koverse/xml/example/books/1.0.0"
           xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="http://www.koverse/xml/example/books/1.0.0">
  
  <xs:element name="books" type="tns:books"/>
  
  <xs:complexType name="books" final="extension restriction">
    <xs:sequence>
      <xs:element name="book" type="tns:book" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="book" final="extension restriction">
    <xs:sequence>
      <xs:element name="author" type="xs:string"/>
      <xs:element name="title" type="xs:string"/>
    </xs:sequence>
    <xs:attribute name="id" type="xs:string"/>
  </xs:complexType>

</xs:schema>

Now, to transform this XML into XML that represents Koverse records, the following XSLT would be used:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" 
  xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  xmlns:b="http://www.koverse/xml/example/books/1.0.0"
  xmlns="http://www.koverse/xml/records/1.0.0">

  <xsl:output method="xml" indent="yes"/>
  
  <xsl:template match="/">
    <records>
      
      <xsl:for-each select="b:books/b:book">
        <record>
          
          <securityLabel></securityLabel>
          
          <fields>
            
            <entry>
              <entry-name>id</entry-name>
              <entry-value xsi:type="decimal">
                <value>
                  <xsl:value-of select="@id"/>
                </value>
              </entry-value>
            </entry>
            
            <entry>
              <entry-name>author</entry-name>
              <entry-value xsi:type="string">
                <value>
                  <xsl:value-of select="b:author"/>
                </value>
              </entry-value>
            </entry>
            
            <entry>
              <entry-name>title</entry-name>
              <entry-value xsi:type="string">
                <value>
                  <xsl:value-of select="b:title"/>
                </value>
              </entry-value>
            </entry>
            
          </fields>
          
        </record>
      </xsl:for-each>
      
    </records>
  </xsl:template>
  
</xsl:stylesheet>

Which would produce the following XML file that conforms to the Koverse Record XML Schema:

<?xml version="1.0" encoding="UTF-8"?>
<records xmlns:b="http://www.koverse/xml/example/books/1.0.0" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xmlns="http://www.koverse/xml/records/1.0.0">
  
  <record>
    <securityLabel/>
    <fields>
      <entry>
        <entry-name>id</entry-name>
        <entry-value xsi:type="decimal">
          <value>1</value>
        </entry-value>
      </entry>
      <entry>
        <entry-name>author</entry-name>
        <entry-value xsi:type="string">
          <value>Miguel De Cervantes</value>
        </entry-value>
      </entry>
      <entry>
        <entry-name>title</entry-name>
        <entry-value xsi:type="string">
          <value>Don Quixote</value>
        </entry-value>
      </entry>
    </fields>
  </record>
  
  <record>
    <securityLabel/>
    <fields>
      <entry>
        <entry-name>id</entry-name>
        <entry-value xsi:type="decimal">
          <value>2</value>
        </entry-value>
      </entry>
      <entry>
        <entry-name>author</entry-name>
        <entry-value xsi:type="string">
          <value>John Bunyan</value>
        </entry-value>
      </entry>
      <entry>
        <entry-name>title</entry-name>
        <entry-value xsi:type="string">
          <value>Pilgrim's Progress</value>
        </entry-value>
      </entry>
    </fields>
  </record>
  
  <record>
    <securityLabel/>
    <fields>
      <entry>
        <entry-name>id</entry-name>
        <entry-value xsi:type="decimal">
          <value>3</value>
        </entry-value>
      </entry>
      <entry>
        <entry-name>author</entry-name>
        <entry-value xsi:type="string">
          <value>Daniel Defoe</value>
        </entry-value>
      </entry>
      <entry>
        <entry-name>title</entry-name>
        <entry-value xsi:type="string">
          <value>Robinson Crusoe</value>
        </entry-value>
      </entry>
    </fields>
  </record>
  
</records>

Finally, for your reference, here is the complete Koverse XML Schema:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema elementFormDefault="qualified" version="1.0" 
           xmlns:tns="http://www.koverse/xml/records/1.0.0" 
           xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="http://www.koverse/xml/records/1.0.0" >

  <xs:element name="records" type="tns:records"/>

  <xs:complexType name="boolean" final="extension restriction">
    <xs:complexContent>
      <xs:extension base="tns:scalar-field">
        <xs:sequence>
          <xs:element name="value" type="xs:boolean"/>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <xs:complexType name="scalar-field" abstract="true">
    <xs:complexContent>
      <xs:extension base="tns:field">
        <xs:sequence/>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <xs:complexType name="field" abstract="true">
    <xs:sequence/>
  </xs:complexType>

  <xs:complexType name="date" final="extension restriction">
    <xs:complexContent>
      <xs:extension base="tns:scalar-field">
        <xs:sequence>
          <xs:element name="value" type="xs:dateTime"/>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <xs:complexType name="array" final="extension restriction">
    <xs:complexContent>
      <xs:extension base="tns:container-field">
        <xs:sequence>
          <xs:element name="element" type="tns:field" maxOccurs="unbounded"/>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <xs:complexType name="container-field" abstract="true">
    <xs:complexContent>
      <xs:extension base="tns:field">
        <xs:sequence/>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <xs:complexType name="map" final="extension restriction">
    <xs:complexContent>
      <xs:extension base="tns:container-field">
        <xs:sequence>
          <xs:element name="entry" type="tns:entry" maxOccurs="unbounded"/>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <xs:complexType name="entry" final="extension restriction">
    <xs:sequence>
      <xs:element name="entry-name" type="xs:string"/>
      <xs:element name="entry-value" type="tns:field"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="records" final="extension restriction">
    <xs:sequence>
      <xs:element name="record" type="tns:record" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="record" final="extension restriction">
    <xs:sequence>
      <xs:element name="securityLabel" type="xs:string"/>
      <xs:element name="fields" type="tns:map"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="string" final="extension restriction">
    <xs:complexContent>
      <xs:extension base="tns:scalar-field">
        <xs:sequence>
          <xs:element name="value" type="xs:string"/>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <xs:complexType name="decimal" final="extension restriction">
    <xs:complexContent>
      <xs:extension base="tns:scalar-field">
        <xs:sequence>
          <xs:element name="value" type="xs:decimal"/>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
</xs:schema>