XML to XML mapping to upgrade schema version with XSLT?
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 43
- Joined: Tue Jul 26, 2016 6:31 pm
XML to XML mapping to upgrade schema version with XSLT?
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:
The output format will look similar:
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 ()?
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!
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>
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>
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!
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: XML to XML mapping to upgrade schema version with XSLT?
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
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
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service