[prev in list] [next in list] [prev in thread] [next in thread] 

List:       opennms-devel
Subject:    [opennms-devel] [PATCH] Add a XSL transformation to pretty print
From:       kernel-hacker () bennee ! com
Date:       2011-04-04 17:36:09
Message-ID: 1301938569-22991-2-git-send-email-kernel-hacker () bennee ! com
[Download RAW message or body]

From: Alex Bennee <ajb@cbnl.com>

As our support guys would like to review all the event/alarm messages that
are presented to our users I wrote this XSL transformation. It will take
the eventconf.xml (or any subfile) and transform it into more readable
(when rendered in the browser) XHTML.
---
 opennms-doc/src/xslt/events_to_html.xslt |  149 ++++++++++++++++++++++++++++++
 1 files changed, 149 insertions(+), 0 deletions(-)
 create mode 100644 opennms-doc/src/xslt/events_to_html.xslt

diff --git a/opennms-doc/src/xslt/events_to_html.xslt \
b/opennms-doc/src/xslt/events_to_html.xslt new file mode 100644
index 0000000..d47e1d1
--- /dev/null
+++ b/opennms-doc/src/xslt/events_to_html.xslt
@@ -0,0 +1,149 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+    Transform an OpenNMS event definition file into something printable.
+
+    To generate some xhtml from an event definition file:
+    
+    xsltproc -o output.xhtml opennms-doc/src/xslt/events_to_html.xslt \
opennms-base-assembly/src/main/filtered/etc/eventconf.xml +-->
+<xsl:stylesheet version="1.0"
+		xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+		xmlns="http://www.w3.org/1999/xhtml"
+		xmlns:ec="http://xmlns.opennms.org/xsd/eventconf">
+ 
+  <xsl:output method="xml" indent="yes" encoding="UTF-8"/>
+
+  <!-- root node processing -->
+  <xsl:template match="/">
+    <html>
+      <head>
+        <title>Summary of OpenNMS Event Definitions</title>
+      </head>
+      <body>
+	<xsl:apply-templates select="ec:events"/>
+      </body>
+    </html>
+  </xsl:template>
+
+  <xsl:template match="ec:events">
+    <h2>A set of events</h2>
+    <xsl:apply-templates select="ec:event">
+      <xsl:sort select="ec:event/ec:uei"/>
+    </xsl:apply-templates>
+    <xsl:apply-templates select="ec:event-file"/>
+  </xsl:template>
+
+  <!-- process event file inclusions -->
+  <xsl:template match="ec:event-file" xml:space="preserve">
+    <div>file includes another file</div>
+    <xsl:apply-templates select="document(.)"/>
+  </xsl:template>
+
+  <!--
+      Used to clean out html tags from embedded descriptions.
+
+      See: http://blog.thekid.me.uk/archive/2007/05/17/stripping-html-tags-when-using-xslt.aspx
 +  -->
+  
+  <xsl:template name="strip_html_tags">
+    <xsl:param name="html"/>
+    <xsl:choose>
+        <xsl:when test="contains($html, '&lt;')">
+            <xsl:value-of select="substring-before($html, '&lt;')"/>
+            <!-- Recurse through HTML -->
+            <xsl:call-template name="strip_html_tags">
+                <xsl:with-param name="html" select="substring-after($html, \
'&gt;')"/> +            </xsl:call-template>
+        </xsl:when>
+        <xsl:otherwise>
+            <xsl:value-of select="$html"/>
+        </xsl:otherwise>
+    </xsl:choose>
+  </xsl:template>
+
+  <!--
+      The main transformation, transform an event into neat (X)HTML
+  -->
+  <xsl:template match="ec:event" xml:space="preserve">
+    <h2><xsl:value-of select="ec:uei"/></h2>
+    <xsl:apply-templates select="./ec:mask"/>
+    <xsl:apply-templates select="./ec:severity"/>
+    <xsl:apply-templates select="./ec:event-label"/>
+    <xsl:apply-templates select="./ec:logmsg"/>
+    <xsl:apply-templates select="./ec:alarm-data"/>
+    <xsl:apply-templates select="./ec:descr"/>
+    <xsl:apply-templates select="./ec:operinstruct"/>
+    
+  </xsl:template>
+
+  <xsl:template match="ec:mask" xml:space="preserve">
+      <b>Source:</b>SNMP Trap 
+      <xsl:value-of select="./ec:maskelement[1]/ec:mevalue"/>.
+      <xsl:value-of select="./ec:maskelement[2]/ec:mevalue"/>.
+      <xsl:value-of select="./ec:maskelement[3]/ec:mevalue"/>
+      <br/>
+  </xsl:template>
+
+  <xsl:template match="ec:severity" xml:space="preserve">
+    <b>Severity:</b> <xsl:value-of select="."/><br/>
+  </xsl:template>
+
+  <xsl:template match="ec:event-label" xml:space="preserve">
+    <b>Event Label:</b> <xsl:value-of select="."/><br/>
+  </xsl:template>
+
+  <xsl:template match="ec:logmsg" xml:space="preserve">
+    <b>Log Message:</b> <xsl:value-of select="."/><br/>
+  </xsl:template>
+
+  <xsl:template match="ec:alarm-data" xml:space="preserve">
+    <xsl:variable name="alarm_type" select="./@alarm-type" />
+    <hr/>
+    <xsl:if test="$alarm_type=1">
+      This Event will <b>generate</b> Alarms<br/>
+      <b>Reduction Key:</b><xsl:value-of select="./@reduction-key"/>
+      <xsl:if test="./@auto-clean">
+	(previous matching events will be deleted)
+      </xsl:if>
+      <br/>      
+    </xsl:if>
+    <xsl:if test="$alarm_type=2">
+      This Event will <b>clear</b> Alarms<br/>
+      <b>Reduction Key:</b><xsl:value-of select="./@reduction-key"/><br/>      
+      <xsl:if test="./@clear-key">
+	<b>Will clear alarms with a key of:</b><xsl:value-of	select="./@clear-key"/><br/>
+      </xsl:if>
+    </xsl:if>
+    <xsl:if test="$alarm_type&gt;2">
+      This Event has an odd alarm-type of <xsl:value-of select="./@alarm-type"/>
+    </xsl:if>
+    <hr/>
+  </xsl:template>
+
+  <xsl:template match="ec:descr">
+    <xsl:variable name="descr_pure_text">
+      <xsl:call-template name="strip_html_tags">
+        <xsl:with-param name="html" select="." />
+      </xsl:call-template>
+    </xsl:variable>
+
+    <b>Description:</b>
+    <pre>
+      <xsl:value-of select="$descr_pure_text"/>
+    </pre>
+  </xsl:template>
+
+  <xsl:template match="ec:operinstruct">
+    <xsl:variable name="oper_pure_text">
+      <xsl:call-template name="strip_html_tags">
+        <xsl:with-param name="html" select="." />
+      </xsl:call-template>
+    </xsl:variable>
+
+    <b>Operator Instructions:</b>
+    <pre>
+      <xsl:value-of select="$oper_pure_text"/>
+    </pre>
+  </xsl:template>
+
+</xsl:stylesheet>
-- 
1.7.4.3


------------------------------------------------------------------------------
Create and publish websites with WebMatrix
Use the most popular FREE web apps or write code yourself; 
WebMatrix provides all the features you need to develop and 
publish your website. http://p.sf.net/sfu/ms-webmatrix-sf
_______________________________________________
Please read the OpenNMS Mailing List FAQ:
http://www.opennms.org/index.php/Mailing_List_FAQ

opennms-devel mailing list

To *unsubscribe* or change your subscription options, see the bottom of this page:
https://lists.sourceforge.net/lists/listinfo/opennms-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic