The following code relates to the earlier post and shows the processing of a concatenated XML file using an XSLT. This has been tested using a Xalan on the command line but this is available as XML::Xalan.
Example of concatenated XML reports:
<?xml version="1.0"?>
<Report>
<opt>
<Agent_Class>Backup</Agent_Class>
<MD>dirA</MD>
<Agent_Instance>NetBackup</Agent_Instance>
<Date>2003/12/08</Date>
<Server>ServerABC</Server>
<Instance_Detail>Backup Problems ServerABC:57</Instance_Detail>
<Time>08:04:58</Time>
<Header>X-CALL</Header>
<State>CRITICAL</State>
</opt>
<opt>
<Agent_Class>Backup</Agent_Class>
<MD>dirA</MD>
<Agent_Instance>NetBackup</Agent_Instance>
<Date>2003/12/08</Date>
<Server>ServerABC</Server>
<Instance_Detail>Backup Problems ServerABC:57</Instance_Detail>
<Time>08:04:58</Time>
<Header>X-CALL</Header>
<State>CRITICAL</State>
</opt>
<opt>
<Agent_Class>Backup</Agent_Class>
<MD>dirB</MD>
<Agent_Instance>NetBackup</Agent_Instance>
<Date>2003/12/08</Date>
<Server>ServerABC</Server>
<Instance_Detail>Backup Problems ServerABC:57</Instance_Detail>
<Time>09:00:58</Time>
<Header>X-CALL</Header>
<State>Nominal</State>
</opt>
</Report>
Example of XSLT to do the conversion:
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" />
<xsl:preserve-space elements="*"/>
<!-- Transforms the XML report into an HTML report -->
<xsl:template match="/">
<html>
<head>
<title>Server Status Report</title>
</head>
<body>
<xsl:comment>Generated file</xsl:comment>
<h1>Server Status Report</h1>
<p/>
<table border="1">
<xsl:for-each select="Report/opt">
<xsl:sort select="MD"/>
<tr>
<td><xsl:value-of select="MD" /></td>
<td><xsl:value-of select="Server" /> <xsl:value-of select="Ag
+ent_Class" /></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><xsl:value-of select="Instance_Detail" /></td>
<td><xsl:value-of select="Date" /> <xsl:value-of select="Date
+" /></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:transform>
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|