Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: schema comparer

From: "Michael Kay" <mike@--------.--->
To: "'Bryan Rasmussen'" <brs@----.-->, <xmlschema-dev@--.--->
Date: 1/31/2005 11:00:00 AM
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@w... 
> [mailto:xmlschema-dev-request@w...] On Behalf Of Bryan Rasmussen
> Sent: 31 January 2005 10:45
> To: 'xmlschema-dev@w...'
> 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>
> 


From brs@i... Mon Jan 31 11:20:53 2005
Received: from lisa.w3.org ([128.30.52.41])
	by frink.w3.org with esmtp (Exim 4.34)
	id 1CvZbx-0000Ka-AL
	for xmlschema-dev@li


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent