NIST tests for datatypes

David Tolpin <[email protected]>
Newsgroups gmane.text.xml.relaxng.general
Message-ID <[email protected]>
Hi,

there is a NIST testsuite that checks XML schema datatypes for conformance,

http://xw2k.sdct.itl.nist.gov/brady/schema/NISTSchemaTests.zip

Below are two simple transformations that convert xml schema test files 
(there are 1117 tiny schema files) into Relax NG (or Relax NG Compat).

Could be useful for implementors and users.

David Tolpin

<!-- XML -->
<xsl:transform xmlns="http://relaxng.org/ns/structure/1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0">
  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="/">
    <grammar
      datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"
      ns='{concat(/xsd:schema/xsd:element/@name,"-NS")}'>
      <start>
	<element name="{/xsd:schema/xsd:element/@name}">
	  <optional>
	    <attribute name="xsi:schemaLocation"/>
	  </optional>
	  <data>
	    <xsl:apply-templates select="/xsd:schema/xsd:simpleType[1]/xsd:restriction"/>
	  </data>
	</element>
      </start>
    </grammar>

  </xsl:template>  

  <xsl:template match="xsd:restriction">
    <xsl:attribute name="type"><xsl:value-of select="@base"/></xsl:attribute>
    <xsl:for-each select="*">
       <param>
          <xsl:attribute name="name"><xsl:value-of select="name()"/></xsl:attribute>
	  <xsl:value-of select="@value"/>
       </param>
    </xsl:for-each>
  </xsl:template>
</xsl:transform>

<!-- Compact -->

<xsl:transform xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="text"/>

  <xsl:template match="/">
    default namespace = "<xsl:value-of select="/xsd:schema/xsd:element/@name"/>-NS" 
    namespace xsi = "http://www.w3.org/2001/XMLSchema-instance"

    start = element <xsl:value-of select="/xsd:schema/xsd:element/@name"/> { 
      attribute xsi:schemaLocation { text } ? ,
      <xsl:apply-templates select="/xsd:schema/xsd:simpleType[1]/xsd:restriction"/>
    }
  </xsl:template>  

  <xsl:template match="xsd:restriction">
      xsd:<xsl:value-of select="@base"/> {
	<xsl:for-each select="*">
	   <xsl:value-of select="name()"/>="<xsl:value-of select="@value"/>"
	</xsl:for-each>
      }
  </xsl:template>
</xsl:transform>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.