Open XML page with reference to XSL stylesheet based on form submission

Hello Experts,

I have been trying to figure out how to even ask this question because I wasn't familiar with XML and XSL stylesheets until now. Now that I understand what needs to happen, I'm hoping that someone can help me with the code to do this. I'm assuming that i need to use PHP, but I'm open to suggestions.

I want to provide people with a form that has a couple of fields, but for now, let's just say that I'm only giving them one code. They enter a zip code, they click submit. What I'm looking to do is to take the information typed into that input field and add it on to a URL string that will always be the same. So, for instance, if someone types in 89436 the URL would be or if someone types in 75757 the URL would be

Now, the URL that is created above is returning a ton of XML data that I want to apply an XSL stylesheet to. So, ultimately what I'm trying to do is once that submit button is clicked I want to open the URL that is created (which is NOT on a server that I control) and apply a stylesheet to it.

Any ideas? I've tried asking this before, but again, I didn't fully understand what I was trying to do. Please provide as much detail as you can.....thank you!
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

What i would in this situation is use cURL for requesting the XML from the remote server.
Once you have a copy of it, then you can apply your own XSL stylesheet to it, then output it.

$zip = isset($_GET['zip']) ? trim($_GET['zip']) : '89436';

$url = ''.$zip;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$xml_output = curl_exec($ch);

/* Apply your stylesheet reference by manipulating the XML output */

// echo $xml_output;

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ray PaseurCommented:
Absent the specifics like the actual URL and the test data, we can only tell you about the general terms of the design pattern.

For a form to add information to a URL, you would use a GET method request.  Try this script:
<?php // RAY_temp_ambientsbs.php ?>
<form action="RAY_bounce_get.php" method="get">
<input type="text"   name="location" />
<input type="submit" name="whatever" value="Go!" />

Open in new window

That script makes a post to another script that shows you how to get the contents of the URL.
<?php // RAY_bounce_get.php
echo "<pre>" . PHP_EOL;

Open in new window

The XML/XSL part of this is really a separate learning exercise.  Start with var_dump() to visualize whatever the remote site produces.  If is valid XML, you might try using SimpleXML methods to put it into an object so you can use parts of the XML string without having to use all of it.

This may be helpful:
ambientsbsAuthor Commented:
Thank you both for your replies! I will try these solutions out and get back shortly with any questions or to let you know if one of the solutions worked. MUCH appreciated!!
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

ambientsbsAuthor Commented:
Hi Ray Soloman,

I've finally had a chance to get to this piece and am wondering what my code needs to look like in the sections where you indicated:

/* Apply your stylesheet reference by manipulating the XML output */

// echo $xml_output;

Sorry, I'm not great at PHP so any insight you can give would be helpful. Thanks!
Ray PaseurCommented:
Please read this brief piece, then use the Google search suggested after it.  There is no short answer unless you have budget to pay a professional programmer to write your code for you.  If you do, then time is money and you can exchange one for the other.

When the question includes, I didn't fully understand what I was trying to do that is almost always a good time to call in the pro!  There is nothing wrong with getting professional help.  I do not work on my cars or design the interiors of my office -- these are things better left to those with direct subject matter experience.

Best of luck with it, ~Ray
ambientsbsAuthor Commented:
Thanks for your input, but honestly, I have to disagree a little bit Ray Paseur. Being new to this type of project, but still having a basic understanding of coding in general, sometimes it just takes a little guidance. Both of your comments were helpful but I ended up figuring out how to do this on my own. Here is the code that I created:

$zip = Trim(stripslashes($_POST['Zip']));

$xsl = new DOMDocument();
$xsl -> load("");
$xml = new DOMDocument();
$xml -> load(''.$zip);

$proc = new XSLTProcessor();
$proc -> importStylesheet($xsl);

echo $proc -> transformtoXML($xml);


And it works PERFECTLY.......
ambientsbsAuthor Commented:
This solution got me to the final solution which I've posted....
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.