Link to home
Start Free TrialLog in
Avatar of FesterWim
FesterWim

asked on

Automatic XSL Generator

I'm using JAXB to store the configuration of my program. Ofcourse the XML Schema's I use change my application grows. I want to have a XSL transformation that transforms the XML in the old format to the new format. I have XML Schema's describing both formats and there are only elements added, never removed.
Is there a program that creates the XSL automatically?
I have looked at XSLerator, but it does not do what I want.
Avatar of SuperKarateMonkey
SuperKarateMonkey

It seems that you wouldn't actually need a separate program, but rather just an intelligent XSL Stylesheet.

My first guess would be to take the 3 XML files, (the source XML file, as well as the two schemas,) and merge them into one uber-DOM.  From there you'd be able to move back and forth between the three, reading from the two schemas and modifying the source to match.

I worked with XSL Stylesheets at my previous job, and you can pretty much use them to do just about anything to a DOM that you might like.  Gimme an example of what you're trying to do, with the 2 sample Schemas, and I think I might be able to help.

Avatar of FesterWim

ASKER

Yes, I just need a XSL stylesheet, that is true. But I want a program that creates this stylesheet for me. So I can apply the XSL transform to the original XML file and it should be converted to conform to the new XSD. Should I mail you the XML files because they might be a bit big to post here (about 150 lines each)
Yeah, see, that's my point:  You won't need a program to write XSL Stylesheets.  You just want a Stylesheet that's lot more intelligent than you think.  See, what I'm imagining is that you could take your three XML files, and mash them together into one big DOM.  Nothing fancy, just create one root node and append each of them to it.  Then for each node in the old schema, your stylesheet could move into the new schema, find the changes that needed to be made, and then finally move into the source xml and apply said changes.

You don't need to send me the whole files.  Just post up here a snippet of code from each of the three files that are relevant:

1.  From the old schema a snippet that has the definition of a particular node.
2.  From the new schema a snippet that REDEFINES said node.
3.  From the source xml an example of the OLD node.
4.  Optionally, what the example node should look like post-transformation.

Though the fourth snippet isn't essential, (it should be implied by the second one,) it'd be nice for verification.
Ok, got the idea now. That would be very nice if that would be possible. But I don't know much about XSL, so that's why I thought that a program would be easier for me...

SOURCE XSD:
<xs:element name="doelstellingenlijst">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="doelstelling" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

TARGET XSD:
<xs:element name="doelstellingenlijst">
  <xs:complexType>
    <xs:sequence>
      <xs:element ref="doelstelling" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>
<xs:element name="doelstelling">
   <xs:complexType>
     <xs:sequence>
      <xs:element name="doelstelling" type="xs:string" minOccurs="1" maxOccurs="1"/>
      <xs:element name="linkedlesverloop" type="xs:string" minOccurs="0" />
    </xs:sequence>
  </xs:complexType>
</xs:element>

SOURCE XML:
<doelstellingenlijst>
  <doelstelling>nieuwe doelstelling2</doelstelling>
  <doelstelling>nieuwe doelstelling1</doelstelling>
<doelstellinglijst>

RESULTING XML:
<doelstellingenlijst>
  <doelstelling>
    <doelstelling>nieuwe doelstelling2</doelstelling>
    <linkedlesverloop></linkedlesverloop>
  </doelstelling>
  <doelstelling>
    <doelstelling>nieuwe doelstelling1</doelstelling>
    <linkedlesverloop></linkedlesverloop>
  </doelstelling>
</doelstellingenlijst>
ASKER CERTIFIED SOLUTION
Avatar of SuperKarateMonkey
SuperKarateMonkey

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
P.S. - You might be able to get more assistance in the XSL area of this site, as this is rapidly becoming an XSL question, not a java question.

The xml area can be found at:

https://www.experts-exchange.com/Web/Web_Languages/XML/
Hmm.. I still think I'm going to have do to way to much for the purpose I need it for. I have 2 beta testers and I want convert their configuration to the new format. Probably the easiest would be for me to spend a weekend learning XSL and writing something myself. Those AddChild and CreateChild templates will probably be very handy.

After a little search I found that what I probably really want is this:
http://www.xmlspy.com/features_xml2xml_mapforce.html

I will try out the trial and see if it does what I want
This Mapforce thing defenitely takes the work out of my hands. It generates a XSL file from the 2 XSD files I give. I just needed to tweak the generated XSL file a bit, and I could convert my old configuration without problems.
I suppose that's fine.