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.
LVL 1
FesterWimAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SuperKarateMonkeyCommented:
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.

0
FesterWimAuthor Commented:
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)
0
SuperKarateMonkeyCommented:
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.
0
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

FesterWimAuthor Commented:
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>
0
SuperKarateMonkeyCommented:
OK, this isn't impossible.  What you're going to need to do is identify the cases you can face with modifying the DOM.  There probably aren't going to be an unbounded series of them.  For example the cases would be the "AddChild" case, where you essentially add a child and then output the next node(s), and "CreateChild," where you just create an empty child node.  In this one you'd need XSL applied ot the source XML that looked like this:

<xsl:template match="doelstelling">
  <doelstelling>
    <xsl:apply-templates select="text()[normalize-space(.) != ''][1]" mode="AddChild">
      <xsl:with-param name="NodeName">doelstelling</xsl:with-param>
    </xsl:apply-templates>
    <xsl:call-template name="createChild">
      <xsl:with-param name="NodeName">linkedlesverloop</xsl:with-param>
    </xsl:call_template>
  </doelstelling>
</xsl:template>

<xsl:template match="*" mode="AddChild">
  <xsl:element name="{$NodeName}">
    <xsl:value-of select="normalize-space(.)" />
  </xsl:element>
</xsl:template>

<xsl:template name="CreateChild">
  <xsl:element name="{$NodeName}"/>
</xsl:template>

Now, the tricky bit here is having the stylesheet RECOGNIZE which mode it's going to have to alter the source xml with.  That I can't help you with, since you've got the whole span of what and how things can be changed, but basically instead of just calling these templates, the stylesheet will need to recognize a node called xs:element name="doelstelling"> and go out to the new schema to find the corrolary element, interrogate the new child elements of that node, (if any,) and then call/apply the appropriate templates against the source document.

It's not an easy problem, but coding a java program to dynamically write XSL is probably harder, and more time consuming.  At my old job I did both and the former was definitely the better way to go, I think.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SuperKarateMonkeyCommented:
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:

http://www.experts-exchange.com/Web/Web_Languages/XML/
0
FesterWimAuthor Commented:
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
0
FesterWimAuthor Commented:
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.
0
SuperKarateMonkeyCommented:
I suppose that's fine.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.