|
| |||||||||
| Tags: display, java, transform, xml, xslt |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| ||||
| ||||
| 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. |
|
#2
| ||||
| ||||
| 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> |
|
#3
| |||
| |||
| 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:
|
|
#4
| ||||
| ||||
| 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:
|
|
#5
| ||||
| ||||
| 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> |
![]() |
|
| Thread Tools | Search this Thread |
| |
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 |