File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes HTML to XSLT  and vice versa  generation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "HTML to XSLT  and vice versa  generation" Watch "HTML to XSLT  and vice versa  generation" New topic
Author

HTML to XSLT and vice versa generation

jeff rusty
Ranch Hand

Joined: Nov 07, 2006
Posts: 109
Hi all,

I need to generate an XSLT from a HTML and then to combine the XSLT with an xml file to populate data and convert it back to a HTML report.
HTML(with empty data) --------> XSLT ---------> XSLT+XML------->HTML(with data)
Is there is any tool already available to do this? if not how can i acheieve this?

Any help would be appreciated.

Regards,
jeff
Aryan Khan
Ranch Hand

Joined: Sep 12, 2004
Posts: 290

Dont know of any tools which can do this.

But one approach might be to write an xsl stylesheet to convert HTML to XSL first.

Then this XSL can then be applied to an XML to generate the HTML with data.

Aryan


OCP/MCP/SCJP/SCWCD/IBM XML/SCMAD/SCEA-1
jeff rusty
Ranch Hand

Joined: Nov 07, 2006
Posts: 109
i dont want to write the XSL instead i want it to be automatically generated based on the HTML.

Jeff
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12675
    
    5
You might find it easier to convert your HTML to a Velocity template.

Bill


Java Resources at www.wbrogden.com
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
i dont want to write the XSL instead i want it to be automatically generated based on the HTML.


Can you provide a few examples of the proposed conversion between HTML elements and XSL elements?

For instance, what would a <h4> convert to? Or, what would a <div> convert to?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18114
    
    8

Converting HTML to XSLT seems implausible to me, too. I would like to see an example of how this would work.
jeff rusty
Ranch Hand

Joined: Nov 07, 2006
Posts: 109
For instance, what would a <h4> convert to? Or, what would a <div> convert to?


I am not sure of what will it convert since i am a novice in XSL.I am trying to generate my HTML reports dynamically using the XSLT and XML data and i found that Xalan & Saxon does this very well but i dont want the developers to wirte the XSLT instead i want them to make a proptotype (HTML) of the report with static data and would like to convert it in to a XSLT which adhers to the XML and later on this generated XSLT along with my XML data can transform to a HTML with data populated dynamiclly...

Is it possible to generate XsLT from a HTML automatically?

thanks ,
jeff
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18114
    
    8

So, you have an undescribed XML file which is going to be your input, an HTML file which is going to be your output, and an XSLT file which transforms the input to the output. Pretty normal so far.

Now you hope to design an HTML "template" which will somehow represent an idealized form of your output, and you want to take that and somehow generate the XSLT file which does the transformation. I don't see any mention of the XML file which is the input, so if your answer is "yes" then it doesn't matter what's in that XML file. It could even be a bare root element with no content at all. And that's clearly not right. Therefore your answer is "no". The XSLT must have some dependence on the input document.
jeff rusty
Ranch Hand

Joined: Nov 07, 2006
Posts: 109
I don't see any mention of the XML file which is the input


I will pass an XML along with the HTML to generate the XSLT file and that XML will contain the Data in the format required for generating the HTML page. In such a case is it possible to get the XSLT?


Jeff
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Is it possible to generate XsLT from a HTML automatically?


Your idea is possible. However, the software needs to be created. I'm not aware of any commercial, proprietary, or open-source product that does what your idea entails.

Good luck!
[ July 15, 2008: Message edited by: James Clark ]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18114
    
    8

Yes, every couple of years some new product comes out where you provide the format of the output and it magically produces a program that produces your output from your data. These products are marketed enthusiastically to IT managers and usually end up on a shelf in the server room. I have become cynical about whether program-writing programs are a realistic goal. I don't think they are.

In your case the XSLT is going to include rules like "A <customer> element will be converted to a <table> element, and an <invoice> element will be converted to a <td> element inside that..." and so on. Generally it takes a certain amount of intelligence to intuit those rules by just looking at the inputs and the outputs. It can't be done automatically by a dumb program. And when it can, then the next transformation you need to write turns out to be more complicated than that and your program doesn't work any more. (I'm thinking of my 700-line transformation which turns XML invoices into HTML.)

I'm not saying it couldn't be done. I'm just saying it hasn't been done and you can't do it. And it isn't worthwhile for you to try.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HTML to XSLT and vice versa generation
 
Similar Threads
Q for Dmitry Kirsanov : XSLT's value
generate xslt
Is Javaranch RSS Enabled?
How to avoid server calls in Sorting
Html Report