tags:

views:

54

answers:

2

Hi All,

I have the following XML file:

<graph caption="Share Data Wave" subcaption="For Person's Name" xAxisName="Time"  yAxisMinValue="-0.025" yAxisName="Voltage" decimalPrecision="5" formatNumberScale="0" numberPrefix="" showNames="1" showValues="0" showAlternateHGridColor="1" AlternateHGridColor="ff5904" divLineColor="ff5904" divLineAlpha="20" alternateHGridAlpha="5">
     <set name="2010-08-27 12:00:20.636" value="25.020000" hoverText = "The difference from last value: 0" ></set>
     <set name="2010-08-27 12:01:19.473" value="15.000000" hoverText = "The difference from last value: -10.02" ></set>
     <set name="2010-08-27 12:01:24.494" value="15.020000" hoverText = "The difference from last value: 0.0199999999999996" ></set>
     <set name="2010-08-27 12:01:44.188" value="18.250000" hoverText = "The difference from last value: 3.23" ></set>
     <set name="2010-08-27 12:02:11.851" value="18.540000" hoverText = "The difference from last value: 0.289999999999999" ></set>
     <set name="2010-08-27 12:02:47.109" value="16.520000" hoverText = "The difference from last value: -2.02" ></set>
     <set name="2010-08-27 12:03:01.199" value="17.500000" hoverText = "The difference from last value: 0.98" ></set>
     <set name="2010-08-27 12:03:03.030" value="25.020000" hoverText = "The difference from last value: 7.52" ></set>
     <set name="2010-08-27 12:03:40.570" value="30.000000" hoverText = "The difference from last value: 4.98" ></set>
     <set name="2010-08-27 12:04:27.490" value="32.250000" hoverText = "The difference from last value: 2.25" ></set>
     <set name="2010-08-27 12:05:03.738" value="26.050000" hoverText = "The difference from last value: -6.2" ></set>
     <set name="2010-08-27 12:05:14.511" value="18.540000" hoverText = "The difference from last value: -7.51" ></set>
     <set name="2010-08-27 12:06:09.728" value="16.520000" hoverText = "The difference from last value: -2.02" ></set>
     <set name="2010-08-27 12:06:58.329" value="17.500000" hoverText = "The difference from last value: 0.98" ></set>
</graph>

Is there a way in PHP to alter this file to display just some of the data points say between 2010-08-27 12:02:11.851 (start time) to 2010-08-27 12:05:03.738 (end time) and to give the user a drop down menu of the start time and a drop down menu of the finish time while maintaining the top tag and the bottom tag?

Any suggestions?

Regards,

Anthony

A: 

It's possible. E.g. via XSL(T). Many browsers can do this even on the client side.
see http://www.w3.org/TR/xslt and http://docs.php.net/book.xsl

VolkerK
A: 

First you should ask yourself if you actually want to alter the file. It sounds like you actually want to use this file as input and use PHP to generate an HTML file with your drop down menu.

I think Volker's right that you probably want to use XSLT. Basically it is a kind of stylesheet that will transform an XML document into something else. But you can also use it to perform tests, which is how you would select the date range you want.

Here's a basic tutorial on XSLT: http://www.w3schools.com/xsl/xsl_transformation.asp (but it won't tell you what you need to know to select your date range).

Your XSL file would look something like this (I think -- this is not tested):

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" 
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:php="http://php.net/xsl"&gt;
<xsl:output method="html" encoding="utf-8" indent="yes"/>
 <xsl:template match="/graph">
  <html><body>
    <select>
    <xsl:for-each select="set">
          <xsl:if test="php:function('testDate',string(@name))"/>
      <option value="">
        <xsl:value-of select="php:function('formatDate',string(@name))"/>
      </option>
      </xsl:if>
    </xsl:for-each>
    </select>
  </body></html>
 </xsl:template>
</xsl:stylesheet>

In this case, you'd be writing functions to test whether the date matches the range you set (testDate), and to format the date the way you want (formateDate; see strtotime() and date() functions). Also you'd need to figure out what value you want to pass back when the form is submitted. And then follow this example to get PHP to use this XSL file to parse the XML file: http://docs.php.net/manual/en/xsltprocessor.registerphpfunctions.php

handsofaten
At present the xml file is used by FusionCharts Free to construct a Flash graph. I want to be able to alter the xml file so that a new flash graph can be produced (a "drill-down" effect, as if to zoom in on a particular time period). The purpose of the drop down menu would be to allow the user pick the time period.
Anthony Keane
Oh, I see. It seems like you would want to use JavaScript to do that. Instead of editing the XML file and reloading the page, you can pass in data dynamically. And there is a FusionCharts jQuery plugin:http://www.fusioncharts.com/jquery/
handsofaten
This is proving problematic. I have downloaded the file but am having trouble getting it to work.
Anthony Keane
Check out this post:http://www.shamasis.net/2010/03/jquery-plugin-for-fusioncharts-1-0-0b/
handsofaten