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" />&#160;<xsl:value-of select="Ag +ent_Class" /></td> <td>&#160;</td> </tr> <tr> <td>&#160;</td> <td><xsl:value-of select="Instance_Detail" /></td> <td><xsl:value-of select="Date" />&#160;<xsl:value-of select="Date +" /></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:transform>

In reply to Re: Re: Fast processing of XML files for CGI by inman
in thread Fast processing of XML files for CGI by AcidHawk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.