【发布时间】:2015-05-17 07:23:17
【问题描述】:
您好,我想将我的 xml 数据转换为 HTML 报告。我的示例 xml 如下所示。
<?xml version="1.0" encoding="UTF-8"?>
<TestCases>
<TestCase>
<TCiD>TC001</TCiD>
<Scenario>Verify the login functionality</Scenario>
<TSResult>Pass</TSResult>
<ScTime>50</ScTime>
<Steps>
<Step>Invoke application and enter a valid "Username"</Step>
<Method>enter_Text</Method>
<TestData>muralitharan_qac_mem</TestData>
<StepResult>Pass</StepResult>
<Time>08/05/15 14:34:27 </Time>
<Filepath>SanpFilePath</Filepath>
</Steps>
<Steps>
<Step>Enter the valid "Password"</Step>
<Method>enter_Password</Method>
<TestData>test!</TestData>
<StepResult>Pass</StepResult>
<Time>08/05/15 14:34:27 </Time>
<Filepath></Filepath>
</Steps>
<Steps>
<Step>Tap on the submit button</Step>
<Method>click_On_Button</Method>
<TestData></TestData>
<StepResult>Pass</StepResult>
<Time>08/05/15 14:34:27 </Time>
<Filepath></Filepath>
</Steps>
<Steps>
<Step>Tool wait time</Step>
<Method>ToolToWaitInMilliSeconds</Method>
<TestData>10000</TestData>
<StepResult>Pass</StepResult>
<Time>08/05/15 14:34:27 </Time>
<Filepath></Filepath>
</Steps>
</TestCase>
<TestCase>
<TCiD>TC002</TCiD>
<Scenario>Verify unsuccessful login for invalid Username</Scenario>
<TSResult>Pass</TSResult>
<ScTime>60</ScTime>
<Steps>
<Step>Invoke application and enter a invalid "Username"</Step>
<Method>enter_Text</Method>
<TestData>invalid_mem</TestData>
<StepResult>Pass</StepResult>
<Time>08/05/15 14:34:27 </Time>
<Filepath>SanpFilePath</Filepath>
</Steps>
<Steps>
<Step>Enter the valid "Password"</Step>
<Method>enter_Password</Method>
<TestData>test2!</TestData>
<StepResult>Pass</StepResult>
<Time>08/05/15 14:34:27 </Time>
<Filepath></Filepath>
</Steps>
<Steps>
<Step>Tap on the submit button</Step>
<Method>click_On_Button</Method>
<TestData></TestData>
<StepResult>Pass</StepResult>
<Time>08/05/15 14:34:27 </Time>
<Filepath></Filepath>
</Steps>
</TestCase>
</TestCases>
现在我希望我的 html 报告是这样的:
TestCase Testcase Name Result Time
TC001 Verify the login functionality Pass 50
TC002 Verify unsuccessful login for Pass 60
invalid Username
点击 TC001 后,测试用例的相关步骤将显示为表格(类似于可以展开或折叠的树结构)。
谁能帮我解决这个问题。
我创建的 xslt 在表格中显示了测试用例,但我无法为这些步骤创建树结构。 xslt 如下所示。
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:s="http://www.stylusstudio.com/xquery">
<xsl:template match="/">
<html>
<head />
<body>
<div style="text-align: none;color: #0000FF;">
<table align="none" style="border-style: outset;border-width: 2pt;width: 100%;background-repeat: repeat" cellspacing="1pt">
<tbody>
<tr>
<td style="border-style: inset;border-width: 2pt;padding: 2pt;vertical-align: middle;background-repeat: repeat">
<div style="text-align: none;color: #0000FF;">
<span style="font-weight: bold;text-decoration: underline;">
<xsl:text>Test Case ID</xsl:text>
</span>
</div>
</td>
<td style="border-style: inset;border-width: 2pt;padding: 2pt;vertical-align: middle;background-repeat: repeat">
<div style="text-align: none;color: #0000FF;">
<span style="font-weight: bold;text-decoration: underline;">
<xsl:text>Test Case Name</xsl:text>
</span>
</div>
</td>
<td style="border-style: inset;border-width: 2pt;padding: 2pt;vertical-align: middle;background-repeat: repeat">
<div style="text-align: none;color: #0000FF;">
<span style="font-weight: bold;text-decoration: underline;">
<xsl:text>Result</xsl:text>
</span>
</div>
</td>
<td style="border-style: inset;border-width: 2pt;padding: 2pt;vertical-align: middle;background-repeat: repeat">
<div style="text-align: none;color: #0000FF;">
<span style="font-weight: bold;text-decoration: underline;">
<xsl:text>Execution Time (Seconds)</xsl:text>
</span>
</div>
</td>
</tr>
<xsl:for-each select="/TestCases/TestCase">
<xsl:variable name="TestCase" select="." />
<tr>
<td style="border-style: inset;border-width: 2pt;padding: 2pt;vertical-align: middle;background-repeat: repeat">
<div style="text-align: none;color: #0000FF;">
<xsl:value-of select="TCiD" />
</div>
</td>
<td style="border-style: inset;border-width: 2pt;padding: 2pt;vertical-align: middle;background-repeat: repeat">
<div style="text-align: none;color: #0000FF;">
<xsl:value-of select="Scenario" />
</div>
</td>
<td style="border-style: inset;border-width: 2pt;padding: 2pt;vertical-align: middle;background-repeat: repeat">
<div style="text-align: none;color: #0000FF;">
<xsl:value-of select="TSResult" />
</div>
</td>
<td style="border-style: inset;border-width: 2pt;padding: 2pt;vertical-align: middle;background-repeat: repeat">
<div style="text-align: none;color: #0000FF;">
<xsl:value-of select="ScTime" />
</div>
</td>
</tr>
</xsl:for-each>
</tbody>
</table>
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
【问题讨论】:
-
你已经尝试过什么了吗? - 将 XSLT 代码添加到您的帖子中。
-
在我看来这不是一个 XSLT 问题,而是一个网页设计问题(HTML + Javascript)。看起来您想知道要使用什么 HTML,即转换的输出是什么(而不是使用什么转换来实现您已经知道的某些输出)。如果您知道要生成什么,然后发布它,我们将能够在 XSLT 方面为您提供帮助。
-
@potame 我已经添加了我创建的 xslt,但它只为我的工作提供了一半。请帮帮我。
-
您使用(或打算使用)什么来创建消耗性结构?我认为@FlorentGeorges 是对的,这个问题首先与网页设计有关。
-
@potame 根据您的要求,我添加了我创建的 XSLT。但是我无法为这些步骤创建树结构,你能帮我吗