Subject: [xsl] Ann: XML Schema Evolver From: Corwin Joy <corwinjoy@xxxxxxxxx> Date: Sun, 30 May 2010 18:54:01 -0700 |
What: This tool helps create scripts to migrate XML data from one version of an XML schema to a later version of the same schema. The tool creates these scripts by differencing XSD files and emitting XSLT 2.0 to automatically migrate XML data. Where: https://sourceforge.net/projects/xsdevolver/ Background: The company I work for sells a shrink-wrapped application where we save a workbook in an XML format according to a specified XSD schema. Over time, we expect the format of this schema to change. We wanted a way to help us diff schema versions as they evolve over time and generate initial XSLT to migrate data from older versions of the schema to newer versions of the schema. Details: Usage: XMLSchemaEvolver SchemaVersion1.xsd SchemaVersion2.xsd Output: 1. A schema diff showing what elements have been changed 2. XSLT to translate XML data from SchemaVersion1 to SchemaVersion2 How does it work? The basic idea is this: 1) Do a diff of two xml schema (xsd) files. 2) Each change is classified as an INSERT, DELETE, MOVE or RENAME operation. 3) For each of these operations, emit simple XSLT to carry out the desired data change. 4) These data change operations are modeled after a set of standard XSLT operations suggested by Jesper Tverskov in XSLT Transformation Patterns. A full list of the transformations emitted by our code can be found XSLT Transformations.txt in the documentation folder. Will this program do everything I will ever need? Probably not. The point of this code is to automate simple changes that are found via differencing. For large complex changes where you need to map multiple values into a single value or massively change a structure you will probably need a data mapping tool. However, this code should help to automate many small simple changes and/or give you starter code that you can build upon to implement more complex changes. Example Suppose we start with the following simple schema to represent an address (see employees.xsd in the Tests directory): <?xml version="1.0"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:emp="http://www.zephyrassociates.com/Zephyr/Employees" targetNamespace="http://www.zephyrassociates.com/Zephyr/Employees"> <xsd:complexType name="Locale"> <xsd:attribute name="region" type="xsd:string" default="US"/> </xsd:complexType> <xsd:complexType name="BaseAddress"> <xsd:complexContent> <xsd:extension base="emp:Locale"> <xsd:sequence> <xsd:element name="street" type="xsd:string"/> <xsd:element name="city" type="xsd:string"/> <xsd:element name="state" type="xsd:string"/> <xsd:element name="zip" type="xsd:string"/> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType> <xsd:complexType name="Address"> <xsd:complexContent> <xsd:extension base="emp:BaseAddress"> <xsd:sequence> <xsd:element name="zip_plus_four" type="xsd:string"/> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType> </xsd:schema> Now we want to rename the attribute in the base type Locale from region to country. So, we have a new schema like (employeesAttributeRename.xsd): <?xml version="1.0"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:emp="http://www.zephyrassociates.com/Zephyr/Employees" targetNamespace="http://www.zephyrassociates.com/Zephyr/Employees"> <xsd:complexType name="Locale"> <xsd:attribute name="country" type="xsd:string" default="US"/> </xsd:complexType> XMLSchemaEvolver will detect the change in the name of the attribute and issue XSLT to change the name of the attribute in the base type and any types that are derived as extensions of this base type (Tests_Out_Expected\employeesAttributeRename_fwd.xslt): <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:emp="http://www.zephyrassociates.com/Zephyr/Employees" > <xsl:import-schema namespace="http://www.zephyrassociates.com/Zephyr/Employees" schema-location="employees.xsd"/> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <!-- ________________________ Final changelist after identifying renamed elements, moved elements, and removing rearrangements that are not part of a sequence. Note. Before we emit the XSLT we remove any inserted root elements or types that did not exist in the old schema since we have no place to put such elements. ________________________ ________________________ Types. Renamed: emp:Locale/@region ==> emp:Locale/@country ________________________ --> <!--Identity transform--> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <!--Update the XML file to point to the new version of the schema--> <xsl:template match="@xsi:schemaLocation"> <xsl:attribute name="xsi:schemaLocation">http://www.zephyrassociates.com/Zephyr/Employees employeesAttributeRename.xsd</xsl:attribute> </xsl:template> <!--Rename the attribute(s) below--> <xsl:template match="element(*, emp:Locale)/@region"> <xsl:attribute name="country" select="."/> </xsl:template> </xsl:stylesheet>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] XSL Dominos, Liam R E Quin | Thread | [xsl] Schema authoring, Karl Stubsjoen |
Re: [xsl] XSL Dominos, Liam R E Quin | Date | [xsl] Schema authoring, Karl Stubsjoen |
Month |