Hi to XSLT-ers, and thanx to Wrox for hosting:
I will describe in detail below my problem, but basically I am trying to pull out data using XSLT / Xpath from an xml document in order to feed simple numbers into Gnuplot. I run xsltproc from the command line (well, a script) on a Linux machine, output those numbers into "traffic.dat", and graph the results by calling gnuplot from the same script.
Here is my input xml (snipped -- basically 24 hours of traffic data every 15 minutes):
Code:
<chart>
<xaxis>
<value xid="0">5/5/09 11:30 am</value>
<value xid="1">5/5/09 11:45 am</value>
<...SNIP...>
<value xid="92">5/6/09 10:30 am</value>
<value xid="93">5/6/09 10:45 am</value>
</xaxis>
<graphs>
<graph gid="1">
<value xid="0">15540.87</value>
<value xid="1">15184.37</value>
<...SNIP...>
<value xid="92">14764.03</value>
<value xid="93">15293.12</value>
</graph>
</graphs>
I would like just a tab delimited file (ideally with rectified ISO dates) like so:
2009-05-06_23:45 14764.03
<... ETC ...>
I would happily settle for just the y-values, throwing out the dates (I can reproduce them more easily than parse the non-iso formats -- grr...), like so:
14764.03
15293.12
....
I have tried the following XSLT file via xsltproc (see version output below):
Code:
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="/chart/graphs/graph/value" >
<xsl:text>mvt=</xsl:text>
<xsl:value-of select="text()" />
</xsl:template>
</xsl:stylesheet>
run as:
Code:
$ xsltproc traffic.xslt traffic.xml
I thought I would get :
mvt=15540.87
... ETC ...
but I get:
Code:
<?xml version="1.0"?>
5/5/09 11:30 am
5/5/09 11:45 am
<... SNIP ...>
5/6/09 10:30 am
5/6/09 10:45 am
<!- note x axis values and whitespace -- I don't really want either! -->
mvt=15540.87
mvt=15184.37
<... SNIP ...>
mvt=14764.03
mvt=15293.12
Output from xsltproc on version:
xsltproc --version <2335>
Using libxml 20626, libxslt 10117 and libexslt 813
xsltproc was compiled against libxml 20626, libxslt 10117 and libexslt 813
libxslt 10117 was compiled against libxml 20626
libexslt 813 was compiled against libxml 20626
If someone can give me the magic recipe for simple numerical output that would be fantastic.
Here is an xmlstarlet (not available on the target machine) invocation that works:
$ xmlstarlet sel -T -t -m /chart/graphs/graph/value -v text() -n traffic.xml
Thanks to all!