Solved

Automatic XSL Generator

Posted on 2003-11-17
11
692 Views
Last Modified: 2012-08-14
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.
0
Comment
Question by:FesterWim
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
11 Comments
 
LVL 2

Expert Comment

by:SuperKarateMonkey
ID: 9764088
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
 
LVL 1

Author Comment

by:FesterWim
ID: 9764298
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
 
LVL 2

Expert Comment

by:SuperKarateMonkey
ID: 9764359
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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 1

Author Comment

by:FesterWim
ID: 9764830
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
 
LVL 2

Accepted Solution

by:
SuperKarateMonkey earned 50 total points
ID: 9765239
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
 
LVL 2

Expert Comment

by:SuperKarateMonkey
ID: 9765256
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
 
LVL 1

Author Comment

by:FesterWim
ID: 9769419
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
 
LVL 1

Author Comment

by:FesterWim
ID: 9785917
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
 
LVL 2

Expert Comment

by:SuperKarateMonkey
ID: 9788257
I suppose that's fine.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question