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.
Indeed it can all be done using XSLT rather than PHP, it's a bit more involved but it can be done. I still have the original XSL file you posted with the original question and have modified it slightly here.
routes.xsl
getbus.php
To allow user to add a route
You need a form, you need to be able to identify the user, you need to have a location to store the generated xml files and probably a whole heap of other things too. So, very quickly:
Here is a pure XSLT solution without PHP. It uses no PHP, no JavaScript (except linking to an off-the-self library). It is pure Html, CSS and XSLT 2.0.
Given this input document, located with relative URL,
buses.xml
...... the interactive bus time-tables can viewed by this host page, with URL ...
... which when loaded by the browser, leverages XSLT 2.0 stylesheet located at url
buses.xsl
...A CSS stylesheet is required at relative url
buses.css
. I used this content, but it is not important. ...And the final resource required is the Saxon/CE library. The resource should be placed at relative url
js/Saxonce/Saxonce.nocache.js
.The outcome
This is the perfect solution. The body of the table dynamically changes to match the user selection of bus. There are no call-backs. All switching is done on the client side, so performance scales very well. Data, html structure, visual styling, and business rules are neatly segregated into separate files. A user can write their own bus routes and save it in the xml file. The whole solution is small and simple.