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[@name=$refOrName
or @ref = $refOrName]/@minOccurs"/>
<xsl:variable name="selectMax"
select="$doc//xsd:complexType[@name=$locname]//xsd:element[@name=$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:47:02 UTC