Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , ,

Sponsored Links



Display a XML and Transform It With XSLT in Java

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 25-02-2010
Level8's Avatar
Member
 
Join Date: Nov 2009
Posts: 873
Display a XML and Transform It With XSLT in Java

Hello everyone, I want to display a XML and then transform it with XSLT. I want this to happen in a JSP page in which I pass the XML file as a parameter in the address bar. So, please help me to achieve it. I will be thankful to you.
Reply With Quote
  #2  
Old 25-02-2010
Praetor's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,937
Re: Display a XML and Transform It With XSLT in Java

Hey, I think you need to make use of the code below and get your problem solved:
Code:
<html>
<head>
<jsp: useBean id ="Test" class="******. DatabaseInteraction " />
<% = String nomdocmnt request.getParameter("Instance");
String str = Test.getInstance(nomdocmnt);
%>
<script>
function loading(fname)
{
var doc;
if (window.ActiveXObject)
  {
  doc =new ActiveXObject("Microsoft.XMLDOM");
  }
else if (docmnt.implementation & & Document.implementation.createDocument)
  {
  doc = docmnt.implementation.createDocument("","",null);
  }
else
  {
  alert('Your browser can not handle this script');
  }
doc.async=false;
doc.load(fname);
return(doc);
}

function disres()
{
xml = loading(str);
xsl = loading("AS5.xsl");
if (window.ActiveXObject)
  {
  ex = xml.transformNode(xsl);
  docmnt.getElementById("example").innerHTML= ex;
  }
else if (docmnt.implementation & & Document.implementation.createDocument)
  {
  XSLTProcessor =new XSLTProcessor();
  XSLTProcessor.importStylesheet (xsl);
  resultDocument = XSLTProcessor.transformToFragment(xml, docmnt);
  docmnt.getElementById("example").appendChild(resultDocument);
  }
}
</ script>
<title> Data Collector </ title>
</ head>
<body id ="example" onLoad ="disres ()">
</ body>
</ html>
Reply With Quote
  #3  
Old 25-02-2010
Member
 
Join Date: May 2008
Posts: 1,990
Re: Display a XML and Transform It With XSLT in Java

There are two ways you could use this XML data in a JSP page:
  • Convert the XML elements into server-side objects and then extract the object properties.
  • Invoke a transformation on the XML data.
XML (Extensible Markup Language) is a set of syntax rules and guidelines for defining text-based markup languages. XML languages have a number of uses including:
  • Exchanging information
  • Defining document types
  • Specifying messages
Reply With Quote
  #4  
Old 25-02-2010
kelfro's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,976
Re: Display a XML and Transform It With XSLT in Java

Hello, I think you need to use the following books for getting the solution for your problem:
  • JavaBeans: Developing Component Software in Java
  • Java Secrets
  • Java Network Programming
  • The Java Developer's Resource
  • The Java Handbook
Reply With Quote
  #5  
Old 25-02-2010
Zecho's Avatar
Member
 
Join Date: May 2008
Posts: 2,267
Re: Display a XML and Transform It With XSLT in Java

Hello, I have created code below for you for displaying a xml and transform it with xslt in java:
Code:
<% @ Page import = "javax.xml.parsers .*"
	import = "org.xml.sax .*" 
	import = "javax.xml.transform .*"
	import = "javax.xml.transform.dom .*"
	import = "javax.xml.transform.stream .*"
	import = "java.io. *"
%>
<html>
<head>
<jsp: useBean id ="database" class="***********. DatabaseInteraction " />
<%
String str = request.getParameter("Instance");
String Instance = database.getInstance(str);
String filename = "AS5.xsl";
DocumentBuilderFactory tfactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dcbuilder = tfactory.newDocumentBuilder();
Document document = dcbuilder.parse(new InputSource(new StringReader(Instance)));
Source source = new DOMSource(document);
File filename = new File(filename);
Result rslt = new StreamResult(filename);
TransformerFactory tfactory = TransformerFactory.newInstance();
Transformer transformer = tfactory.newTransformer();
transform.setOutputProperty(OutputKeys.INDENT, "yes");
transform.setOutputProperty(OutputKeys.Encoding, "ISO-8859-1");
transform.transform(source, rslt);
%>
<title> Data Collector </ title>
</ head>
</ body>
</ html>
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Display a XML and Transform It With XSLT in Java"
Thread Thread Starter Forum Replies Last Post
Use of XSLT Mithun Seth Software Development 5 13-02-2010 01:16 PM
How to Display XML with XSLT? SKREECH Software Development 4 02-02-2010 01:19 AM
Image Display In Java Amaresh Software Development 5 30-01-2010 09:20 AM
Display java applet - chess Gunner 1 Software Development 5 04-01-2010 11:27 AM
Is XSL and XSLT are same Crespin Software Development 3 21-11-2009 05:58 AM


All times are GMT +5.5. The time now is 11:07 AM.