commit b5887ca8b221f2bdb17250015fbe09d96fec5cfb Author: Ondrej Lichtner olichtne@redhat.com Date: Tue May 6 10:01:54 2014 +0200
add result_xslt folder
This folder contains 3 files: xml_to_html.xsl - a XSLT stylesheet that transforms result xml files into a HTML file viewable in a web browser xml_to_html.js - a javascript file that is referenced by the created HTML file, it defines a single function that shows/hides the result data returned by a test xml_to_html.css - a CSS file that is referenced by the created HTML file, it contains some basic formatting
These files should be uploaded to a 'well known' location so that they can be properly linked which will result in a very convenient use of the result xml files - a user opens them in a web browser, and everything just works.
Signed-off-by: Ondrej Lichtner olichtne@redhat.com Signed-off-by: Jiri Pirko jiri@resnulli.us
result_xslt/xml_to_html.css | 23 +++ result_xslt/xml_to_html.js | 21 +++ result_xslt/xml_to_html.xsl | 339 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 383 insertions(+), 0 deletions(-) --- diff --git a/result_xslt/xml_to_html.css b/result_xslt/xml_to_html.css new file mode 100644 index 0000000..2f85bd7 --- /dev/null +++ b/result_xslt/xml_to_html.css @@ -0,0 +1,23 @@ +table.lnst_results td { + padding: 0px 10px 0px 10px; +} + +.result_data{ + background-color: lightgrey; +} + +table.result_data{ + border: 1px solid black; +} + +table.result_data td{ + vertical-align: top; +} + +td.result_pass{ + background-color: lime; +} + +td.result_fail{ + background-color: red; +} diff --git a/result_xslt/xml_to_html.js b/result_xslt/xml_to_html.js new file mode 100644 index 0000000..4c42b66 --- /dev/null +++ b/result_xslt/xml_to_html.js @@ -0,0 +1,21 @@ +window.toggleResultData = function (event, task_id, bg_id) { + switch_display = function(elem){ + if (elem.style.display == 'none') + elem.style.display = ''; + else + elem.style.display = 'none'; + } + + row = event.target.parentNode; + result_row_i = row.rowIndex + 1; + result_row = row.parentNode.rows[result_row_i]; + switch_display(result_row); + + if (task_id !== undefined && bg_id !== undefined){ + rows = row.parentNode.childNodes; + for (i = 0; i < rows.length; ++i){ + if (rows[i].id == ("task_id="+task_id+"bg_id="+bg_id)) + rows[i].style.display = result_row.style.display; + } + } +} diff --git a/result_xslt/xml_to_html.xsl b/result_xslt/xml_to_html.xsl new file mode 100644 index 0000000..7774bbb --- /dev/null +++ b/result_xslt/xml_to_html.xsl @@ -0,0 +1,339 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform%22%3E + <xsl:output method="html" indent="yes"/> + <xsl:template match="/"> + <html> + <body> + <link rel="stylesheet" type="text/css" href="./xml_to_html.xsl"/> + <script type="text/javascript" src="./xml_to_html.js"/> + <h2>LNST results</h2> + <xsl:apply-templates select="results/recipe"/> + </body> + </html> + </xsl:template> + + <xsl:template match="recipe"> + <h3><xsl:value-of select="@name"/></h3> + <table class="lnst_results"> + <tr><th colspan="4">Task</th></tr> + <tr><th>Host</th><th>Command</th><th>Result</th><th>Result message</th></tr> + <xsl:apply-templates select="task"/> + </table> + </xsl:template> + + <xsl:template match="task"> + <tr><th colspan="4">Task <xsl:value-of select="position()"/></th></tr> + <xsl:apply-templates select="command"> + <xsl:with-param name="task_id" select="position()"/> + </xsl:apply-templates> + </xsl:template> + + <xsl:template match="command[@type='exec']"> + <xsl:param name="task_id"/> + <tr> + xsl:choose + <xsl:when test="@bg_id"> + <xsl:attribute name="onclick"> + toggleResultData(event, <xsl:value-of select="$task_id"/>, <xsl:value-of select="@bg_id"/>); + </xsl:attribute> + </xsl:when> + xsl:otherwise + <xsl:attribute name="onclick"> + toggleResultData(event); + </xsl:attribute> + </xsl:otherwise> + </xsl:choose> + <td> + <xsl:value-of select="@host"/> + </td> + <td> + <xsl:value-of select="@command"/> + <xsl:if test="@bg_id"> + bg_id=<xsl:value-of select="@bg_id"/> + </xsl:if> + </td> + <xsl:apply-templates select="result"/> + </tr> + <tr style="display:none;"> + <td></td> + <td colspan="3"> + xsl:choose + <xsl:when test="result_data"> + <xsl:apply-templates select="result_data"/> + </xsl:when> + xsl:otherwise + <div class="result_data"> + This command didn't provide any additional result data. + </div> + </xsl:otherwise> + </xsl:choose> + </td> + </tr> + </xsl:template> + + <xsl:template match="command[@type='ctl_wait']"> + <xsl:param name="task_id"/> + <tr onclick="toggleResultData(event);"> + <td> + Controller + </td> + <td> + wait <xsl:value-of select="@seconds"/>s + </td> + <xsl:apply-templates select="result"/> + </tr> + <tr style="display:none;"> + <td></td> + <td colspan="3"> + xsl:choose + <xsl:when test="result_data"> + <xsl:apply-templates select="result_data"/> + </xsl:when> + xsl:otherwise + <div class="result_data"> + This command didn't provide any additional result data. + </div> + </xsl:otherwise> + </xsl:choose> + </td> + </tr> + </xsl:template> + + <xsl:template match="command[@type='test']"> + <xsl:param name="task_id"/> + <tr> + xsl:choose + <xsl:when test="@bg_id"> + <xsl:attribute name="onclick"> + toggleResultData(event, <xsl:value-of select="$task_id"/>, <xsl:value-of select="@bg_id"/>); + </xsl:attribute> + </xsl:when> + xsl:otherwise + <xsl:attribute name="onclick"> + toggleResultData(event); + </xsl:attribute> + </xsl:otherwise> + </xsl:choose> + <td> + <xsl:value-of select="@host"/> + </td> + <td> + <xsl:value-of select="@module"/> + <xsl:if test="@bg_id"> + bg_id=<xsl:value-of select="@bg_id"/> + </xsl:if> + </td> + <xsl:apply-templates select="result"/> + </tr> + <tr style="display:none;"> + <td></td> + <td colspan="3"> + xsl:choose + <xsl:when test="result_data"> + <xsl:apply-templates select="result_data"/> + </xsl:when> + xsl:otherwise + <div class="result_data"> + This command didn't provide any additional result data. + </div> + </xsl:otherwise> + </xsl:choose> + </td> + </tr> + </xsl:template> + + <xsl:template match="command[@type='config']"> + <xsl:param name="task_id"/> + <tr onclick="toggleResultData(event);"> + <td> + <xsl:value-of select="@host"/> + </td> + <td> + config + </td> + <xsl:apply-templates select="result"/> + </tr> + <tr style="display:none;"> + <td></td> + <td colspan="3"> + xsl:choose + <xsl:when test="result_data"> + <xsl:apply-templates select="result_data"/> + </xsl:when> + xsl:otherwise + <div class="result_data"> + This command didn't provide any additional result data. + </div> + </xsl:otherwise> + </xsl:choose> + </td> + </tr> + </xsl:template> + + <xsl:template match="command[@type='intr']"> + <xsl:param name="task_id"/> + <tr onclick="toggleResultData(event);"> + <td> + <xsl:value-of select="@host"/> + </td> + <td> + interrupt bg_id=<xsl:value-of select="@proc_id"/> + </td> + <xsl:apply-templates select="result"/> + </tr> + <tr style="display:none;"> + <xsl:attribute name="id">task_id=<xsl:value-of select="$task_id"/>bg_id=<xsl:value-of select="@proc_id"/></xsl:attribute> + <td></td> + <td colspan="3"> + xsl:choose + <xsl:when test="result_data"> + <xsl:apply-templates select="result_data"/> + </xsl:when> + xsl:otherwise + <div class="result_data"> + This command didn't provide any additional result data. + </div> + </xsl:otherwise> + </xsl:choose> + </td> + </tr> + </xsl:template> + + <xsl:template match="command[@type='kill']"> + <xsl:param name="task_id"/> + <tr onclick="toggleResultData(event);"> + <td> + <xsl:value-of select="@host"/> + </td> + <td> + kill bg_id=<xsl:value-of select="@proc_id"/> + </td> + <xsl:apply-templates select="result"/> + </tr> + <tr style="display:none;"> + <xsl:attribute name="id">task_id=<xsl:value-of select="$task_id"/>bg_id=<xsl:value-of select="@proc_id"/></xsl:attribute> + <td></td> + <td colspan="3"> + xsl:choose + <xsl:when test="result_data"> + <xsl:apply-templates select="result_data"/> + </xsl:when> + xsl:otherwise + <div class="result_data"> + This command didn't provide any additional result data. + </div> + </xsl:otherwise> + </xsl:choose> + </td> + </tr> + </xsl:template> + + <xsl:template match="command[@type='wait']"> + <xsl:param name="task_id"/> + <tr onclick="toggleResultData(event);"> + <td> + <xsl:value-of select="@host"/> + </td> + <td> + wait for bg_id=<xsl:value-of select="@proc_id"/> + </td> + <xsl:apply-templates select="result"/> + </tr> + <tr style="display:none;"> + <xsl:attribute name="id">task_id=<xsl:value-of select="$task_id"/>bg_id=<xsl:value-of select="@proc_id"/></xsl:attribute> + <td></td> + <td colspan="3"> + xsl:choose + <xsl:when test="result_data"> + <xsl:apply-templates select="result_data"/> + </xsl:when> + xsl:otherwise + <div class="result_data"> + This command didn't provide any additional result data. + </div> + </xsl:otherwise> + </xsl:choose> + </td> + </tr> + </xsl:template> + + <xsl:template match="result"> + xsl:choose + <xsl:when test="@result='PASS'"> + <td class="result_pass">PASSED</td> + </xsl:when> + xsl:otherwise + <td class="result_fail">FAILED</td> + </xsl:otherwise> + </xsl:choose> + <td> + <xsl:if test="message"> + <xsl:value-of select="message"/> + </xsl:if> + </td> + </xsl:template> + + <xsl:template match="result_data"> + <table class="result_data"> + <th>Result Data:</th> + <xsl:for-each select="*"> + <xsl:call-template name="res_data_dict_item"/> + </xsl:for-each> + </table> + </xsl:template> + + <xsl:template name="res_data_dict_item"> + <tr> + <td> + <xsl:value-of select="local-name()"/> + </td> + <td> + xsl:choose + <xsl:when test="@type = 'list'"> + <ul> + <xsl:for-each select="*"> + <li> + <xsl:call-template name="res_data_list_item"/> + </li> + </xsl:for-each> + </ul> + </xsl:when> + <xsl:when test="@type = 'dict'"> + <table class="result_data"> + <xsl:for-each select="*"> + <xsl:call-template name="res_data_dict_item"/> + </xsl:for-each> + </table> + </xsl:when> + xsl:otherwise + <xsl:value-of select="text()"/> + </xsl:otherwise> + </xsl:choose> + </td> + </tr> + </xsl:template> + + <xsl:template name="res_data_list_item"> + xsl:choose + <xsl:when test="@type = 'list'"> + <ul> + <xsl:for-each select="*"> + <li> + <xsl:call-template name="res_data_list_item"/> + </li> + </xsl:for-each> + </ul> + </xsl:when> + <xsl:when test="@type = 'dict'"> + <table class="result_data"> + <xsl:for-each select="*"> + <xsl:call-template name="res_data_dict_item"/> + </xsl:for-each> + </table> + </xsl:when> + xsl:otherwise + <xsl:value-of select="text()"/> + </xsl:otherwise> + </xsl:choose> + </xsl:template> +</xsl:stylesheet>
lnst-developers@lists.fedorahosted.org