Bear Bibeault wrote:What problems are you having?
Bear Bibeault wrote:So you had problems with the XSLT approach and you just abandoned it rather than seeking help on why it "didn't work"?
![]()
Rahul Divedi wrote:I have to convert from one HTML to another HTML through a java program (or if there is any other efficient method). Both the HTML files differ little bit in structure. Can anyone please help me out in this matter?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Rahul Divedi wrote:I have to convert from one HTML to another HTML through a java program (or if there is any other efficient method). Both the HTML files differ little bit in structure. Can anyone please help me out in this matter?
"Differ a little bit" doesn't really help much. How do they differ? Exactly.
Winston
Rahul Divedi wrote:Please look at both the files for the complete differences...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Rahul Divedi wrote:Please look at both the files for the complete differences...
No, you tell us. Presumably this isn't the only piece of HTML that needs to be converted, so there must be some rules involved. What are they?
To be honest, if you list them out, it'll probably be a major step in working out a solution.
Winston
Rahul Divedi wrote:Yes this is not the only piece of HTML, there are more files but all of them have same structure. These are the files containing some quiz questions, so in the sample code I have included only one question while there can be many. First difference between the source and desired HTML files is the 'Javascripts'. I have copied those Javascripts from package B to A, which were not present there and now those 3 Javascripts should be included in the desired HTML file and one javascript has to be excluded from the source file. This remains true for all the HTML files and not affected by the number of questions in the quiz.
Second difference is the desired HTML Body tag should be like <body onload="loadPage()" onunload="unloadPage()"> while in the source it is like <body>.
Third difference is there is a Form tag <form name="quizForm8" id="quizForm8" action="javascript:calcScore2();"> in the desired one, which is not there in the source (action event is important).
Fourth one is <input type="radio" name="option1b12" id="true1b12" onclick="getFeedback(0,2,'1b12','truefalse')"/> , here I need to eliminate this onclick event.
Last one is that there should be a submit button in the desired file. <input type="submit" name="submitB" value="SUBMIT ANSWERS"/></div></div></form>
These rules remain same for all the HTML files.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Paul Clapham wrote:Well, fortunately your HTML is actually XHTML (at least the first couple of lines claim it is), so you should be able to use XSLT.
If your goal is a transformation which leaves the document basically the same except for a few modifications, then what you should do is to start with the identity transformation and add some templates which do those modifications. Your requirement to change the <body> element, for example: you need a template which handles a <body> element by writing out a revised <body> element and calling xsl:apply-template for its contents.
And don't forget that all of your elements are in a namespace. Don't make the mistake of treating them as if they aren't. Declare the "http://www.w3.org/1999/xhtml" namespace with a prefix and use that prefix in your XSLT.
Winston Gutkowski wrote:
Right. Now we have something to work with. Personally, I'd look at a solution based on a simple parser like Sax. That way you can look for tags by name and simply replace the attributes or contents as you need. The alternative (which I wouldn't recommend), is simply to treat the whole thing as a big String edit: read the file into a big String, replace whatever contents you need, and then write it out again.
The first will take a bit more work (including possible conversion to XHTML), but it's a lot more generic, so if you have any files with the same basic content but slightly different format (different tag order perhaps), the changes should still work. It's also good practise.
Winston

Paul Clapham wrote:Well, fortunately your HTML is actually XHTML (at least the first couple of lines claim it is), so you should be able to use XSLT.
If your goal is a transformation which leaves the document basically the same except for a few modifications, then what you should do is to start with the identity transformation and add some templates which do those modifications. Your requirement to change the <body> element, for example: you need a template which handles a <body> element by writing out a revised <body> element and calling xsl:apply-template for its contents.
And don't forget that all of your elements are in a namespace. Don't make the mistake of treating them as if they aren't. Declare the "http://www.w3.org/1999/xhtml" namespace with a prefix and use that prefix in your XSLT.
| Consider Paul's rocket mass heater. |