Dynamic XSLT generation based on changes in XSD
Asked Answered
M

2

7

Initially I had various XSD definition for each XSD I had set of XML files stored.

After some time duration there are some changes in XSD definition so my stored XML is no more validation again new XSD.

For support I need to write XSLT and do changes in my stored XML to validate again new XSD.

Now, in this scenario each time XSD change, I need to write XSLT manually how can I generate this XSLT dynamically.

Currently I am able compare old and new XSD and get the list what is changes using Microsoft.XmlDiffPatch DLL.

Based on this changes I need to generate XSLT using C#.

Medalist answered 1/8, 2017 at 7:58 Comment(2)
After getting the Diff, use Patch Tool.Sielen
This will not help in this case. Because Patch tool compare two XML and do changes in this two. But in my case i need to compare two XSD and what ever changes in structure according changed need to do in respective XML. For this i need to write XSLT.Medalist
A
0

I don't know what your question is, but I think this is technically possible.

It might be easier to just write some c# code that reads the Xml and then augments it and sets it back to the file/database/dataStore.

Accelerando answered 1/8, 2017 at 19:16 Comment(1)
As per my knowledge XSLT is the best option rather then C#.Medalist
C
0

Not sure there is a magic bullet for this. Sounds like you're in for some work, and I'd advise that whatever you do be as reusable as possible in the face of future changes.

You might want to consider using xproc (via Calabash or some other engine) to create an XML pipeline whereby you detect and pass in changes of an XSD into an XSL (perhaps keeping to the convention of one XSL per XSD, to retain your sanity), and then said XSLs take those changes and handle them for all XML files bound by the XSD whose changes are being handled at the moment. Breaking all these into sub-transformations within the pipeline could be possible, and might make things more reusable in the future.

Inside the XSLs you're likely looking at doing something like:

  • for all changes to be made
    • for each XML
      • match/add/delete per element and/or attribute to implement change

One way to represent the changes to be made in some sort of standard format is as an incoming list of operations to perform and associated elements/attrs to act upon (maybe set it up as key/value pairs). Each operation could be a string (add, delete, convert) or a numeric code. You then traverse the list of ops and associated elements and trigger matches to accommodate.

This is all somewhat abstract because I have no idea of the scope or depth of changes you need to make. I'm really just thinking out loud here. You might just have to knuckle down and do some serious one-time work, then implement some sort of change control process to make sure things don't get out of hand in the future.

Hope this helps. Good luck!

Chord answered 18/12, 2019 at 10:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.