September 17th, 2002, 05:49 AM
How can i get data from XML files from a XSL input(como box)?
I design a form using XSL, that has one combo box.
On that,I select one value from the Combo and fetch the corresponding data from XML file and display the data in that same XSL page.
Don't go for the server side to get the selected data.
So how to get the selected data from the Combo?
Kindly reply me as early as possible.
September 17th, 2002, 01:25 PM
Are you saying you already have a way to get the data from the xml file without going back to the server?
As far as I know you can't do this, since the browser doesn't have access the xm file, only the xsl transformed output.
September 17th, 2002, 10:55 PM
Reply to your response.
Tanx for ur rapid reply.
I don't know about XSLT.
My aim to get the selected data in the same page.
I pushed my database data to XML files(for fast acess).
We use XSL to display the data.
But in my form one combobox occured.
So how can i retrieve the selected combo data and how can i display the corresponding(fetching) data?
If any code occurs in XSLT?
Don't go for the serverside.
Otherwise suggest me some code for combo selection in XSLT(in the same page).
Kindly reply me as early as possible.
September 17th, 2002, 11:34 PM
You may have to use something server-side.
What exactly are you trying to do? Be specific, but don't post all of your code
September 17th, 2002, 11:51 PM
Reply to your response.
My XML file namely "aa.xml"
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="bb.xsl"?>
<Node id="n1" switchid="22222">
My XSL file namely "bb.xsl"
<xsl:stylesheet version='1.0' xmlns:xsl ='http://www.w3.org/TR/WD-xsl'>
<form name='f1' method='get' action='xslMaker.jsp'>
<table width='100%' border='1'>
<td><input type='submit' value='Go'/></td>
From the above code how can i retrieve the corresponding data ?
How can i get the selected combo data?
If any other method ocurs?
My aim to select one combo data and display the corresponding data on which seleted.
We already use DOM, but it won't support Netscape.
So only we use XSL.
would u suggest any other method to retrieve data from XML.
September 18th, 2002, 12:12 AM
Couple of questions...
1) What do you want to happen once you pick something from the drop down list?
2) Can you edit xslMaker.jsp? That's a server-side script that could potentially be used for great benefit.
September 18th, 2002, 12:30 AM
<%@ page import="java.io.*" %>
String NodeName=new String(""+request.getParameter("nodename"));
String str_File=new String("");
OutputStream fout=new FileOutputStream("ntar1.xsl");
"<html><body><form name='f1' method='get' action='xslmaker.jsp'>"+
"<table width='100%' border='1'>"+
"<tr><td width='50%'><select name='nodename'>"+
"</xsl:for-each></select></td><td><input type='button' value='Go'/>"+
"</td></tr><tr><td>NodeName'"+NodeName+"'</td></tr><tr><td colspan='2'><xsl:for-each select='NetworkArchitecture/Network/Nodes/Node'>";
"Info <xsl:value-of select='Info'/>"+
"Description <xsl:value-of select='Description'/>"+
"Workgroup <xsl:value-of select='Workgroup'/>"+
"Master <xsl:value-of select='Master'/>"+
"SwitchID <xsl:value-of select='SwitchID'/></pre>"+
out.println("Error while writing");
It will not work comfortablly.
So only we need a code to display and select in the same page.
My aim to select the combo box data and display the contents using XSL.
If any code exists?
my exixting method was fetching selected combo data and move it to the jsp file and that jsp file we re create the XSL file and then redirect that file.
Do you understand my problem?
Otherwise suggest me any other way to achieve my task?
Remember don't go DOM method amd that code will also run in any browser.
September 18th, 2002, 03:14 AM
I don't have time to post code for you right now (bed time here ), but I'll give you some places to look. Let me know if it's not enough and I can try to dig up some code for you tomorrow.
if you have a newer app server or are using jdk 1.4.1, you're set for that. It makes xslt much simpler.
You can use the DOM classes (server-side, not client, so browser isn't an issue) to manage the contents of your xml file and choose which pieces need to be transformed how.
September 18th, 2002, 11:46 PM
Ok, I've got some free time now, I'll see what I can do.
September 19th, 2002, 12:08 AM
For time management only we go for the XSL display.
So our display will be in XSL file only.
How to retrieve the selected data's?
Another Idea: We just move the selected data in to one Xml file.
Then compare with the (Database)XML file.
So give me some idea about that type.
And keep try the exixting method.
My aim is to display only in XSL presentation.
(Data selection and display will be present in the same form.this is my aim)
September 19th, 2002, 01:27 AM
Well, here's some code to play with. You'll have to edit the jsp to have the correct file paths, of course.
September 19th, 2002, 02:00 AM
Thanks for your code...But, my requirement is to do that scripting in xsl itself...We don't want to go for server side scripting....I want to select the data from the xml by using xsl select box. According to the selected value in the select box, the data selection from xml should vary....
We normally do that using server side scripts...but, i would like to implement that in xsl itself...
Kindly help me to implement that...
September 19th, 2002, 10:26 AM
Well, you've got two options then:
1) Have the xsl file respond differently based on which xml tags are passed to it. This would basically be like combining the bb.xsl and cc.xsl files into one. You'd have to have logic in your jsp that processed use input and selected the appropriate tags, though (similar to what is happening now).
2) Pass parameters to the xsl file which are used to perform branching logic. For this you'll need the jsp to process user input and reformat it to pass as parameters to the jsp. Also, xsl isn't the greatest language for branching logic. It's not that bad, but anything else is probably better.
Do either of those sound good to you? Keep in mind that xsl has no way of natively handling user input. It's not designed for that.
September 21st, 2002, 01:58 AM
Doubt in your response!!!
Thanks for your reply. Yesterday, since i was leave to the company, i couldn't response you. Well sir, we implemented the above request in jsp itself with some xml parsers. But, we feel it is very slow. (We are dealing with large amount of data.) So, we planned to shift to XSL by using XQL. But, the user selection is the only problem. Do you have any idea to increase the speed of jsp pages or any better way to implement that request.
Note: Our xml data file is very very larger one.
September 21st, 2002, 03:02 AM
Well, my first reaction is to tell you to put your data back in the database I think you'll ultimately find that faster.
But... going with the xml solution, here are some thoughts.
The speed hit you're taking with the jsp is most likely coming from the xsl transformation. You're not going to be able to avoid this. The example code you posted before handles this by moving the transformation to the client side (the <?xml-stylesheet type="text/xsl" href="bb.xsl"?>), and this helps take the load off the server but doesn't get rid of it.
The only implementation of XQL that I could find was in IE5+, but it's not really called XQL, since they use it as an extension to the DOM.
You might want to look at Kawa for an implementation of XML Query that can be turned into a servlet. This might run faster, but I just found it tonight so I couldn't say.
The jsp code I gave you uses a DOMSource for the initial transform, and you'll probably get speed increase if you use a StreamSource instead, but I'm not sure it will be large enough to notice (it might be, though).
You might be able to use a combination of the first technique with the one I gave you, by using a jsp page to parse an xml file and return just the node you want, then sending an <?xml-stylesheet?> directive to tell the browser how to display it.
Another thing you might try is defining a unique id attribute in a DTD for your xml document, then you could use getElementById() in the jsp page. That would probably work a little faster than the current system, too.
If you're really concerned about speed, though, and your xml file is as big as you're implying, then I think a database is going to be your best option.