XML : Can i use xslt to display drop down menu

Hi I have this done using xml, php and css for styling.

But is it possible to have information in an xml file. And use xslt to display the information in a table. I have a PHP and javascript file as well.

XML file

  <?xml version="1.0"?>    <TT>    <BUS>  <NUMBER>120</NUMBER>      <LEAVING>Howth</LEAVING>  <DESTINATION>Dublin Airport</DESTINATION>  <TIME>06:00, 07:00, 08:10, 9:10, 10:00,  11:25, 12:00, 13:00, 14:00, 15:20, 16:00, 17:00, 18:00</TIME>  </BUS>  </TT>    

PHP

  <?php    $id=$_GET['q'];  $dom=new DOMDocument;  $dom->load( 'routes.xml' );    $col=$dom->getElementsByTagName('NUMBER');    if( $col ){  foreach( $col as $node ){      if( $node->nodeType==XML_ELEMENT_NODE && $node->nodeValue==$id ) {  $parent=$node->parentNode;  }  }      $html=array();  $html[]='  </br>    <table border="2">     <tr>   <th>NUMBER</th>   <th>LEAVING</th>   <th>DESTINATION</th>   <th>TIME</th>   </tr>   <tr>';     foreach( $parent->childNodes as $node ){   if( $node->nodeType==XML_ELEMENT_NODE ) $html[]='<td>'.$node-           >nodeValue.'</td>';   }     $html[]='</tr><tr background-color: #f2f2f2></table>';   echo implode( PHP_EOL, $html );   }         ?>     

JavaScript

  function showBus(str){  if (str==""){  document.getElementById("txtHint").innerHTML="";  return;  }  if (window.XMLHttpRequest) {  // code for IE7+, Firefox, Chrome, Opera, Safari  xmlhttp=new XMLHttpRequest();  } else {  // code for IE6, IE5  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");  }    xmlhttp.onreadystatechange=function() {  if (xmlhttp.readyState==4 && xmlhttp.status==200){  document.getElementById("txtHint").innerHTML=xmlhttp.responseText;  }  }    xmlhttp.open("GET","getbus.php?q="+str,true);  xmlhttp.send();  }        

HTML

  <body>  <form>  <h3>Select your bus route:</h3>  <select name="NUMBER" onchange="showBus(this.value)">  <option value="">Select a Bus:</option>  <option value="15">15</option>  <option value="22">22</option>  <option value="37">37</option>  <option value="44">44</option>  <option value="120">120</option>  </select>  <div id="txtHint"><b>Bus info will be listed here...</b></div>    </form>  </body>  </html>    

I want to display the xml data with each BUS Number in the menu, when you click on the number the information such as destination time is displayed in a table, but i want it using xslt not html.

No comments:

Post a Comment