[XMLSCHEMA-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: schema comparer

From: Michael Kay <mike@saxonica.com>
Date: Mon, 31 Jan 2005 10:59:46 -0000
To: "'Bryan Rasmussen'" <brs@itst.dk>, <xmlschema-dev@w3.org>
Message-Id: <E1CvZHb-0000wa-00@ukmail1.eechost.net>
.xsd matching

You're looking for complex types at any level of nesting and then comparing
them by name. Since named complex types can exist only at the top level, it
would be better to select only the top level complex types for this
comparison. Same applies to simple types.

Obviously this whole exercise is pretty rough-and-ready, for example it's
sensitive to differences in namespace prefixes, but I guess that doesn't
stop it being useful in practice.

Michael Kay 

> -----Original Message-----
> From: xmlschema-dev-request@w3.org 
> [mailto:xmlschema-dev-request@w3.org] On Behalf Of Bryan Rasmussen
> Sent: 31 January 2005 10:45
> To: 'xmlschema-dev@w3.org'
> Subject: schema comparer
> 
> 
> Hey 
> 
> I recently had occasion to write a little schema comparer 
> xslt, doesn't do
> everything, and it limits itself to matching structures based 
> on design
> rules for my work, but  I thought I would post it and see if 
> anyone has any
> comments or improvements, or finds it useful:
> 
> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>  >
> <xsl:output method="xml" indent="yes" />
> <xsl:param name="comparewith" select="'pie/pieComredefines.xsd'"/>
> 
> <xsl:variable name="doc" select="document($comparewith)"/>
> <xsl:template match="/">
> <html><head></head>
> <body>
> <h3/>
> <h3>Complex Type differences</h3>
> <ol>
> <xsl:apply-templates select="//xsd:complexType"/>
> </ol>
> <hr/>
> <h3>ComplexTypes that are added</h3>
> 
> <ol>
> <xsl:apply-templates select="//xsd:complexType" 
> mode="difftypesmode1"/>
> </ol>
> <hr/>
> <h3>SimpleTypes that are added</h3>
> <ol>
> <xsl:apply-templates select="//xsd:simpleType" mode="difftypesmode1"/>
> </ol>
> 
> </body></html>
> </xsl:template>
> 
> <xsl:template match="xsd:complexType" mode="difftypesmode1">
> <xsl:variable name="locname" select="@name"/>
> <xsl:if test="not($doc//xsd:complexType[@name=$locname])">
> <li>the complex type <xsl:value-of select="@name"/> was not 
> found in the
> original document: <xsl:apply-templates
> select="//xsd:element[contains(@type,$locname)]" 
> mode="difftypesanalyze"/> ,
> the structure is <xmp><xsl:copy-of select="."/></xmp></li>
> </xsl:if>
> </xsl:template>
> 
> <xsl:template match="xsd:simpleType" mode="difftypesmode1">
> <xsl:variable name="locname" select="@name"/>
> <xsl:if test="not($doc//xsd:simpleType[@name=$locname])">
> <li>the simple type <xsl:value-of select="@name"/> was not 
> found in the
> original document</li>
> </xsl:if>
> </xsl:template>
> <xsl:template match="*">
> <xsl:param name="locname"/>
> <xsl:apply-templates><xsl:with-param name="locname"
> select="$locname"/></xsl:apply-templates>
> </xsl:template>
> 
> <xsl:template match="xsd:complexType">
> <xsl:variable name="locname" select="@name"/>
> <xsl:apply-templates><xsl:with-param name="locname"
> select="$locname"/></xsl:apply-templates>
> </xsl:template>
> 
> <xsl:template match="xsd:element[ancestor::xsd:complexType]">
> <xsl:param name="locname"/>
> <xsl:variable name="minOccurs" select="@minOccurs"/>
> <xsl:variable name="maxOccurs" select="@maxOccurs"/>
> <xsl:variable name="refOrName" select="concat(@name,@ref)"/>
> <xsl:variable name="selectMin"
> select="$doc//xsd:complexType[@name=$locname]//xsd:element[@na
> me=$refOrName
> or @ref = $refOrName]/@minOccurs"/>
> <xsl:variable name="selectMax"
> select="$doc//xsd:complexType[@name=$locname]//xsd:element[@na
> me=$refOrName
> or @ref = $refOrName]/@maxOccurs"/>
> 
> <xsl:if test="$maxOccurs != $selectMax or $minOccurs != $selectMin">
> 
> <li>element <xsl:value-of select="$refOrName"/> at <xsl:value-of
> select="position()"/> under <xsl:value-of select="$locname"/> 
> is changed:
> current max = <xsl:value-of select="$maxOccurs"/>, old max = 
> <xsl:value-of
> select="$selectMax"/>, current min = <xsl:value-of 
> select="$minOccurs"/>,
> old min = <xsl:value-of select="$selectMin"/></li>
> </xsl:if>
> </xsl:template>
> 
> <xsl:template match="xsd:element" mode="difftypesanalyze">
> it is used by global element <xsl:value-of select="@name"/>
> </xsl:template>
> 
> <xsl:template match="xsd:element[ancestor::xsd:complexType]"
> mode="difftypesanalyze">
> it is used under <xsl:value-of 
> select="ancestor::xsd:complexType/@name"/> ,
> in element <xsl:value-of select="@name"/>, at position <xsl:value-of
> select="count(preceding-sibling::xsd:element) + 1"/>
> </xsl:template>
> 
> </xsl:stylesheet>
> 
Received on Monday, 31 January 2005 10:59:54 GMT

Subscribe to the Stylus Scoop newsletter for helpful XML tips and tutorials.
Email
First Name
Last Name
Company

Download Stylus Studio 6 XML Enterprise Edition

Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.