Welcome to WebmasterWorld Guest from 23.20.230.24

Forum Moderators: httpwebwitch

Message Too Old, No Replies

convert XML to HTML

     
8:29 am on Oct 19, 2007 (gmt 0)

5+ Year Member



I need to convert a receiving XML into HTML, and save it as html.
This has to be done as the application where it later shall be used does not support xml format (only html, tiff and pdf).
So with the xsl I need to run through a directory, and convert all xml into html.
Is there a freeware out there that handles this?
Or does anyone have a good tip?
8:49 am on Oct 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi heggenh and welcome to WebmasterWorld.

The W3 Schools Tutorial [w3schools.com] should provide you with all the information you need.

Marshall

9:27 am on Oct 19, 2007 (gmt 0)

5+ Year Member



I cannot see an answer on the w3.
I have read this site earlier, and the info there is more general and does not cover what I am looking for.
If I have overlooked the answer I would be happy for it to be pointed out.

I have no problem of presenting the data, but I cannot find a way to store it as an html. I need what I see in the browser to be stored as html.

Thanks for all help

9:47 am on Oct 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If I am understanding you correctly, you want to save the final output as viewed in your browser. If that is the case, the easiest method would be open the page in question, view the source code, then save the source code to a new HTML document.

Marshall

10:16 am on Oct 19, 2007 (gmt 0)

5+ Year Member



Yes, that could be a sollution.
But when it is a batch of 1000 files, that will take too long.
So I need to make a script that can do this.
And that is where my problems start.
Does anyone know of something like this made before?
10:35 am on Oct 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld!

You can use XSLT [w3schools.com] and PHP5 [us.php.net]. If you understand how to write XSLT [w3.org], then it is actually not difficult.

I am not aware of any pre-written XSLT [w3.org] scripts to do this, as your XML is probably custom XML.

I use XSLT [w3.org] to transform custom XML into XHTML [w3.org] and WML [w3schools.com].

If you are interested, and know how to use SourceForge Subversion [sourceforge.net], I can direct you to a project that has several XSLT [w3.org] scripts, used to transform custom XML into XHTML [w3.org], JSON [openmobilealliance.org] and WML [openmobilealliance.org] (WML 1.1 [openmobilealliance.org] and XHTML-MP 1.0 [lingvo.org]).

1:57 pm on Oct 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Oops. That should have been JSON [json.org]
2:03 pm on Oct 19, 2007 (gmt 0)

5+ Year Member



I have an XSL that I am using to present XML in a browser, and we have custom written it for the XML.
The problem is that the application later cannot use that XSL.
So I just want to use this XSL in order to get an HTML.
Can I build my xslt on the xsl I have?
Another guy said it should be doable justs by using the xsl.
3:51 pm on Oct 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have an XSL that I am using to present XML in a browser, and we have custom written it for the XML.
The problem is that the application later cannot use that XSL.
So I just want to use this XSL in order to get an HTML.
Can I build my xslt on the xsl I have?
Another guy said it should be doable justs by using the xsl.

It should be fine. I guess that you are sending the XSL to the browser, and the browser is doing the transform.

You can do the same thing on the server, as long as you have an XSLT processor that can run the stylesheet.

I use the PHP 5 XSLT Processor [us.php.net], which works great, as long as you keep your XSL to XSLT 1.0 [w3.org].

1:31 pm on Oct 25, 2007 (gmt 0)

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I don't know of a batch XSLT processor that will do what you need, though I'll admit it would be a handy tool to own.

Sadly I'd suggest writing your own from scratch... the programming wouldn't be too difficult -

iterate through a folder's contents
read the file
transform XML>XSLT>HTML and save as...
loop

You could build it as a server application in PHP/ASP though it may be more portable to build it as a Windows app, ie. with Visual Studio / C#

9:00 pm on Oct 25, 2007 (gmt 0)

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member



oh hey if these files are already on a web server, you can write a mini PHP script that transforms them on demand...

i.e. when someone asks for 12345.htm, you grab 12345.xml and transform it then output the result. one script, which handles all requests with a little rewrite rule in the .htaccess

RewriteRule (.*).htm transform.php?id=$1

then in the php...


$filename = $_GET['id'];
// load the file
// transform it
// print() the output

that's a paltry example in pseudocode, but that's the general idea

I've employed that technique to offer the same data in multiple formats, eg. "mydata.xml", "mydata.json", "mydata.html", "mydata.csv", "mydata.txt" etc - all handled by the same script, with multiple XSLT options

 

Featured Threads

Hot Threads This Week

Hot Threads This Month