Show XML as webpage

Posted on 2011-04-26
Last Modified: 2012-05-11
Hello Experts!

I've searched the entire Internet looking for an answer to this question and am hoping that someone here can help me figure out how to do this:

I want to create a webpage with a form that has just a few fields. Those fields would be "location", "size", and "gender". Once somebody enters one or all of the values in this form and presses Submit, I would like a URL passed to an XSLT page (which is an XML source) containing the values that were selected.

So, for instance, someone selects Austin,TX as their location, size as Small, and gender as female from the form. When they click submit, the URL that I then want referenced in my XSLT page that would then open would be,tx&size=small.

Can ANYONE tell me how to do this?? Thank you in advance!!!
Question by:ambientsbs
    LVL 38

    Expert Comment

    by:Tom Beck
    I'm thinking you would want users to select sex and size from dropdowns or checkboxes. With javascript you could redirect with something like this:

    <script type="text/javascript">

    var sexObj = document.getElementById('sexOption');
    var selIndex = sexObj.selectedIndex;
    var locText = documentGetElementById("locTextbox").value;
    var sizeObj = document.GetElementById('sizeOption');
    var sizeIndex = sizeObj.selectedIndex;

    function onSubmit() {
        window.location = "" + sexObj.options[selIndex].value + "&location=" + locText + "&size=" + sizeObj.options[sizeIndex].value;


    Author Comment

    Thanks for the feedback! I definitely agree that the sex and size should be dropdowns and would create them like that.

    So from what I'm reading, clicking the I would be setting up the form so that once someone clicks "submit" they would be redirected to the

    That leads me to 2 questions:

    1. I would want to REQUIRE that someone enter a location, but the size and sex aren't necessary. Would this javascript work correctly in the case that they were to leave those other fields blank?

    2. Using this method, how do I tie my xml stylesheet to the page?

    Thank you so much !
    LVL 38

    Accepted Solution

    1. You should provide a default selected index that would yeild an empty string so if the user does not make a selection, the javascript will still work. Better still, you could check to see if a value has been entered first before splicing together the redirect url. If nothing was selected, shorten the query string to just the queries(s) you have values for.

    2. I'm assuming you have some kind of server side script that parses the query string for the selections made and returns a result based on those selections. For example, your pet.find could in reality be pet.php. When pet.php is requested via the redirect (with query included), some php script would run on the server side that is able to extract a subset of the XML based on the query string and return the results back to the client. I suppose you could do it all with client side scripting but you would have to expose the entire XML file to the client for every request.

    Author Comment

    Thanks for the feedback and sorry for the delayed reply.

    Makes sense about your first thought, but I do have an issue with the 2nd. The URL that I'm generating,, with the variables from the form I'm creating, is not pulling from a server that I have control over. So, it doesn't seem as if I'd be able to setup a server-side script for this.

    What I would like to do is have somebody click the "Submit" button on the form and redirect to a page on MY server that then references the URL created above and an XML stylesheet that turns that data into something that looks nice. Any suggestions on how to do this?

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Do you want to insert HTML5 video into your site? This is the tutorial how to do so. What are the main advantages of HTML5 video? 1) Have good compression, good image quality, and low decode processor use. 2) It is royalty-free 3) It is easi…
    This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
    The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now