[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 304
  • Last Modified:

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!
0
ambientsbs
Asked:
ambientsbs
  • 4
  • 2
1 Solution
 
ray-solomonCommented:
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.

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

$url = 'http://www.domain.com/abc.find?location='.$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);
curl_close($ch);

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

// echo $xml_output;
?>

0
 
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:
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
0
 
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!!
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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!
0
 
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.
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
0
 
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:


<?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.......
0
 
ambientsbsAuthor Commented:
This solution got me to the final solution which I've posted....
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now