Link to home
Start Free TrialLog in
Avatar of ambientsbs
ambientsbs

asked on

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 field.....zip 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 www.domain.com/abc.find?location=89436 or if someone types in 75757 the URL would be www.domain.com/abc.find?location=75757.

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!
ASKER CERTIFIED SOLUTION
Avatar of ray-solomon
ray-solomon
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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:
http://www.laprbass.com/RAY_temp_ambientsbs.php
<?php // RAY_temp_ambientsbs.php ?>
<form action="RAY_bounce_get.php" method="get">
PLEASE ENTER A ZIP CODE
<input type="text"   name="location" />
<input type="submit" name="whatever" value="Go!" />
</form>

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
error_reporting(E_ALL);
echo "<pre>" . PHP_EOL;
echo "HERE IS THE GET ARGUMENT FROM THE URL:" . PHP_EOL;
var_dump($_GET);

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:
http://www.google.com/?q=Learn+XML+XSL
Avatar of ambientsbs
ambientsbs

ASKER

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!!
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!
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.
http://norvig.com/21-days.html
http://www.google.com/?q=Learn+XML+XSL

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
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:


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


$xsl = new DOMDocument();
$xsl -> load("http://www.mydomain.com/directory/xsl_stylesheet.xsl");
$xml = new DOMDocument();
$xml -> load('http://www.xmldomain.com/results.find?key=12345&location='.$zip);


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

echo $proc -> transformtoXML($xml);

?>

And it works PERFECTLY.......
This solution got me to the final solution which I've posted....