Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to convert XML file to an HTML file using XSLT

 
Ramesh R G V S
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic