This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes How to convert XML file to an HTML file using XSLT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "How to convert XML file to an HTML file using XSLT" Watch "How to convert XML file to an HTML file using XSLT" New topic
Author

How to convert XML file to an HTML file using XSLT

Ramesh R G V S
Greenhorn

Joined: Apr 20, 2002
Posts: 18
Hi All
Is there any way by which i can convert my XML file into an HTML file using XSLT.
As of now i am doing by using
<?xml-stylesheet type="text/xsl" href="cdshow1.xsl"?>
if i do this way i am restricting my xml to one particular view provided by the specified XSL file.
i just want to know is there any way we can use one XML file and different XSL file to generate different views.

Regards
Ramesh R G V S
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Ramesh,
Sure you can. Do do this however, you will need some programming on the server side. For instance from a Java servlet, depending on the client browser (user-agent), you may use one of many stylesheets to transform your XML into HTML.
Apache Cocoon is a framework that provides this feature (among other features).
Cheers
Ramesh R G V S
Greenhorn

Joined: Apr 20, 2002
Posts: 18
Hi
Thanx for the quick reply.You mean i need to generate an HTML from a servlet which will take xml and xsl files and transform to html.
I had written an html for this.But this is working in IE only.Not working in NETSCAPE.Here i am pasting the code.
<html>
<body>
<script language="javascript">
// Load XML
var xml = new ActiveXObject("Microsoft.XMLDOM")
xml.async = false
xml.load("cd.xml")
// Load the XSL
var xsl = new ActiveXObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load("cdshow1_if.xsl")
// Transform
document.write(xml.transformNode(xsl))
</script>
</body>
</html>
Pls let me know if there is other way of doing.

Thanx and regards
Ramesh R G V S
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Ramesh, there is not other reasonable way than to have the HTML produced on the server side.
XSLT transformations on the client side can only be done in Internet Explorer. Maybe some other new web browsers will understand it but it wont work for all of your visitors.
You may also use java applets, but it will only run on webbrowsers that support java applets. And we all know that Windows XP does not ship with a Java Virtual Machine, i.e. all Windows XP visitors won't have a chance to see your pages.
Don't you have access to any programming languages on your web host? Most ISP today allow CGI Scripts (using Perl) at least. You should hence be able to do the XSLT transform using one of the many XSLT modules available.
Good luck
Channy
Greenhorn

Joined: Nov 18, 2002
Posts: 13
You could do it using javax.xml.transform, you can take any xml file and any style sheet and transform it, then I believe output to html, or a file etc.
 
Don't get me started about those stupid light bulbs.
 
subject: How to convert XML file to an HTML file using XSLT
 
Similar Threads
Transforming Huge xml about 50 MB in size
Apache FOP
Apache FOP
using .xml and .xsl file in Servlets/jsp files to generate .html content (to browser)
How to avoid server calls in Sorting