[relaxng-user] NIST tests for datatypes
David Tolpin
dvd at davidashen.net
Mon Dec 29 23:25:11 ICT 2003
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>
More information about the relaxng-user
mailing list