aboutsummaryrefslogtreecommitdiff
path: root/rcynic/rcynic.xsl
blob: e99f3e3895ec247c60959262e5e26bb9c858f379 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?xml version="1.0"?>
<!--
  - Copyright (C) 2006  American Registry for Internet Numbers ("ARIN")
  -
  - Permission to use, copy, modify, and distribute this software for any
  - purpose with or without fee is hereby granted, provided that the above
  - copyright notice and this permission notice appear in all copies.
  -
  - THE SOFTWARE IS PROVIDED "AS IS" AND ARIN DISCLAIMS ALL WARRANTIES WITH
  - REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  - AND FITNESS.  IN NO EVENT SHALL ARIN BE LIABLE FOR ANY SPECIAL, DIRECT,
  - INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  - LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  - OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  - PERFORMANCE OF THIS SOFTWARE.
 --> 

<!-- $Id$ -->

<!--
  - XSL stylesheet to render rcynic's xml-summary output as basic (X)HTML.
  - 
  - This is a bit more complicated than strictly necessary, because I wanted
  - the ability to drop out columns that are nothing but zeros.
  - There's probably some clever way of using XPath to simplify this,
  - but I don't expect the data sets to be large enough for performance
  - to be an issue here.   Feel free to show me how to do better.
 -->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
		version="1.0"
                xmlns:exslt="http://exslt.org/common"
		exclude-result-prefixes="exslt">

  <xsl:output omit-xml-declaration="yes" indent="yes" method="xml" encoding="US-ASCII"
              doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
	      doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>

  <xsl:param name="suppress-zero-columns" select="1"/>

  <xsl:param name="refresh" select="1800"/>

  <xsl:param name="show-total" select="1"/>

  <xsl:variable name="sums">
    <xsl:for-each select="rcynic-summary/labels/*">
      <x sum="{sum(/rcynic-summary/host/*[name() = name(current()) and . != 0])}"/>
    </xsl:for-each>
  </xsl:variable>

  <xsl:template match="/">
    <xsl:comment>Generators</xsl:comment>
    <xsl:comment><xsl:value-of select="rcynic-summary/@rcynic-version"/></xsl:comment>
    <xsl:comment>$Id$</xsl:comment>
    <html>
      <xsl:variable name="title">
        <xsl:text>rcynic summary </xsl:text>
	<xsl:value-of select="rcynic-summary/@date"/>
      </xsl:variable>
      <head>
        <title>
	  <xsl:value-of select="$title"/>
	</title>
	<xsl:if test="$refresh != 0">
	  <meta http-equiv="Refresh" content="{$refresh}"/>
	</xsl:if>
      </head>
      <body>
        <h1>
	  <xsl:value-of select="$title"/>
	</h1>
	<table rules="all" style="text-align: center">
	  <thead>
	    <tr>
	      <xsl:for-each select="rcynic-summary/labels/*">
	        <xsl:variable name="p" select="position()"/>
		<xsl:if test="$suppress-zero-columns = 0 or position() = 1 or exslt:node-set($sums)/x[$p]/@sum &gt; 0">
		  <td>
		    <b>
		      <xsl:apply-templates/>
		    </b>
		  </td>
		</xsl:if>
	      </xsl:for-each>
	    </tr>
	  </thead>
	  <tbody>
	    <xsl:for-each select="rcynic-summary/host">
	      <xsl:sort order="descending" data-type="number" select="sum(*[not(self::hostname)])"/>
	      <xsl:sort order="ascending" data-type="text" select="hostname"/>
	      <tr>
	        <xsl:for-each select="*">
		  <xsl:variable name="p" select="position()"/>
		  <xsl:if test="$suppress-zero-columns = 0 or position() = 1 or exslt:node-set($sums)/x[$p]/@sum &gt; 0">
		    <td>
		      <xsl:if test=". != 0">
		        <xsl:apply-templates/>
		      </xsl:if>
		    </td>
		  </xsl:if>
		</xsl:for-each>
	      </tr>
	    </xsl:for-each>
	    <xsl:if test="$show-total != 0">
	      <tr>
		<td>
		  <b>Total</b>
		</td>
		<xsl:for-each select="exslt:node-set($sums)/x[position() &gt; 1]">
		  <xsl:if test="$suppress-zero-columns = 0 or @sum &gt; 0">
		    <td>
		      <b>
			<xsl:value-of select="@sum"/>
		      </b>
		    </td>
		  </xsl:if>
		</xsl:for-each>
	      </tr>
	    </xsl:if>
	  </tbody>
	</table>
      </body>
    </html>
  </xsl:template>

</xsl:stylesheet>

<!-- 
  - Local variables:
  - mode: sgml
  - End:
 -->