My first foray into the tag soup that is XSL and XSLT has been to turn the XML outputs from the InterNet Barometer System as discussed previously into plain text output which I can use more easily for comparing with some of my other data sources. While A cursory browse cannot find any Terms & conditions for the use of this data, I think I’m on safe ground given that all I’m doing is processing the same xml that is consumed by the flash objects and its not for any kind of commercial use. After hunting around for tools, and wasting a pile of bandwidth on “enterprise editions” I ended up constructing this based on some tutorials at w3c.org using good old vim. I was very tempted to just revert back to sed & awk, or even try my hand at python’s parsing, but decided that I may as well ‘do it right’. The result of a few hours work this evening while watching a filesystem rebuild is shown below:
<?xml version='1.0'?>
<xsl:stylesheet version="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- Barry Irwin bvi@moria.org XSL format for translating XML from interoute Barometer output -->
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>
<xsl:template match="area">
<xsl:value-of select="../../allData/lastUpdated"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="@mc_name"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="@title"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="@value"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="@colour"/>
<xsl:text>
</xsl:text> </xsl:template>
<xsl:template match="allData">
</xsl:template>
This through the magic of xsltproc produces a nice plain text output:
xsltproc map2.xsl asia.xml
given the input from the Asia attack graph produces:
30-06-2009 05:00:17 GMT,RU,Russia,15387,green
30-06-2009 05:00:17 GMT,TR,Turkey,7137,green
30-06-2009 05:00:17 GMT,CN,China,2468,green
30-06-2009 05:00:17 GMT,MY,Malaysia,4158,green
30-06-2009 05:00:17 GMT,IN,India,2631,green
30-06-2009 05:00:17 GMT,TH,Thailand,1823,green
While not the most elegant code, its gets done what I need, and is easily extensible enough to be able to transform to other formats suitable for DB import. I’ll need to monitor data over the next couple of days to get an idea as to how the counters used are actually operating. Once that has been established I can star doing some meaningful comparisons.



0 responses so far ↓
There are no comments yet...Kick things off by filling out the form below.
Leave a Comment