Page 1 of 1

XML to XML mapping to upgrade schema version with XSLT?

Posted: Fri Dec 30, 2016 3:25 pm
by mhGLEIF
I'm putting together an XSLT template to upgrade a single XML file containing multiple "records" and a header to the new version of the same format.

I think this can be done with a relatively small number of modularized standard templates, so I thought I would ask around first before reinventing it.

The source file format looks like this:

Code: Select all



...
<RecordsContainer>
...optional <Header>...
<Record>
...data fields here...
</Record>
... more records...
</RecordsContainer>
The output format will look similar:

Code: Select all



...
<RecordsContainer>
...mandatory <Header>...
<Record>
...data fields here, some identical, some with new element names but same content, and some new/changed in new version...
</Record>
... more records...
</RecordsContainer>
I think I will need templates to do the following:

1. Copy most content as default
2. Upgrade the namespace (new version has a new namespace)
3. Change some element names for the content pasted from the old version of data files
4. Insert placeholder elements as expected by new schema where old schema allowed omission or where new elements are required, sometimes depending on content values (can be checked against code lists or regex)
5. Coordinate some choices which exist in both old and new schemas

I think this can all be nested inside one main template can't it? For the repeating record structure, will I need some XSLT loops (

Code: Select all

for-each
)?

The transform will only be run on valid instances of the schema, so there's no need for error correction.

If anyone can point me to examples of this in the public domain, or a cookbook of templates that can do this or get me started, I'd be very grateful.

Happy 2017 everyone!

Re: XML to XML mapping to upgrade schema version with XSLT?

Posted: Mon Jan 09, 2017 7:20 pm
by adrian
Hi,

1. You need a copy stylesheet that also does the corrections that you need. See Oxygen/samples/xhtml/copy.xsl as a starting point and the idea from this.
2-5. Your best bet is stackoverflow, but searching the web should point you in the right direction.

"for-each" can work, but is rarely the simplest solution in XSLT. You're not thinking of matching templates which is what XSLT is made for.

Regards,
Adrian