Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Location
    INDIA
    Posts
    13
    Rep Power
    0

    How can i get data from XML files from a XSL input(como box)?


    Hai,
    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.
    Regards,
    Pragasam.
  2. #2
  3. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    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.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Location
    INDIA
    Posts
    13
    Rep Power
    0

    Reply to your response.


    Hello,
    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.
    Regards,
    Pragasam.
  6. #4
  7. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    Your problem doesn't have a simple answer, I'm afraid. xsl can't process input from forms, so you're either going to have to use javascript or something server-side.

    Javascript might be an option, depending on what you're trying to do. However, if you're using xsl server-side to generate the html page, you won't be able to access the xml data, so no go.

    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
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Location
    INDIA
    Posts
    13
    Rep Power
    0

    Reply to your response.


    Hello,

    My XML file namely "aa.xml"

    <?xml version="1.0" ?>
    <?xml-stylesheet type="text/xsl" href="bb.xsl"?>
    <NetworkArchitecture>
    <Network>
    <Nodes>
    <Node id="n1" switchid="22222">
    <Type>G</Type>
    <Info>Node Info</Info>
    <Description>Node Description</Description>
    <Workgroup>kgisl</Workgroup>
    <Master>kgisl_pdc</Master>
    <SwitchID>222222</SwitchID>
    </Node>
    </Nodes>
    </Network>
    </NetworkArchitecture>


    My XSL file namely "bb.xsl"

    <xsl:stylesheet version='1.0' xmlns:xsl ='http://www.w3.org/TR/WD-xsl'>
    <xsl:template match='/'>
    <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='NetworkArchitecture/Network/Nodes/Node'>
    <option><xsl:value-of select='@id'/></option>
    </xsl:for-each>
    </select>
    </td>
    <td><input type='submit' value='Go'/></td>
    </tr>
    </table>
    </form>
    </body>
    </html>
    </xsl:template>
    </xsl:stylesheet>


    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.

    Regards,
    Pragasam.
  10. #6
  11. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    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.
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Location
    INDIA
    Posts
    13
    Rep Power
    0

    hello!


    My "xslMaker.jsp"

    <%@ page import="java.io.*" %>
    <%
    String NodeName=new String(""+request.getParameter("nodename"));
    String str_File=new String("");

    OutputStream fout=new FileOutputStream("ntar1.xsl");

    str_File+="<xsl:stylesheet version='1.0'>"+
    "<xmlns:xsl='http://www.w3.org/TR/WD-xsl'><xsl:template match='/'>"+
    "<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='NetworkArchitecture/Network/Nodes/Node'>"+
    "<option><xsl:value-of select='@id'/></option>"+
    "</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'>";

    str_File+="<xsl:if match='.[@id='"+NodeName+"']'>";

    str_File+="<pre>"+
    "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>"+
    "</xsl:if></xsl:for-each></td></tr></table></form>"+
    "</body></html></xsl:template></xsl:stylesheet>";

    try
    {
    fout.write(str_File.getBytes());
    }
    catch(Exception e)
    {
    out.println("Error while writing");
    }
    fout.close();
    response.sendRedirect("aa.xml");
    %>


    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.
    regards,
    Pragasam.
  14. #8
  15. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    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.

    Read this:
    http://java.sun.com/webservices/docs.../JAXPXSLT.html
    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.
  16. #9
  17. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    Ok, I've got some free time now, I'll see what I can do.
  18. #10
  19. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Location
    INDIA
    Posts
    13
    Rep Power
    0

    hello sir,


    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)
    Regards,
    Pragasam.
  20. #11
  21. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    Well, here's some code to play with. You'll have to edit the jsp to have the correct file paths, of course.
    Attached Files
  22. #12
  23. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Location
    INDIA
    Posts
    13
    Rep Power
    0

    XSL display


    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...
  24. #13
  25. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    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.
  26. #14
  27. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Location
    INDIA
    Posts
    13
    Rep Power
    0

    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.
  28. #15
  29. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    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.
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo