关于xslt和javascript的查询
我用xslt编写了将xml文件转换为html文件的代码。该html文件包含表(大约10个表),现在 我的要求是我需要显示“操作”、“跟踪”、“验证”等词在表中出现的次数。我设法处理了jquery JSFIDLE查看我的工作的链接是: 我需要知道是否有任何方法可以单独使用xslt或javascript来实现这一点 我的xslt代码是:关于xslt和javascript的查询,javascript,jquery,xslt,Javascript,Jquery,Xslt,我用xslt编写了将xml文件转换为html文件的代码。该html文件包含表(大约10个表),现在 我的要求是我需要显示“操作”、“跟踪”、“验证”等词在表中出现的次数。我设法处理了jquery JSFIDLE查看我的工作的链接是: 我需要知道是否有任何方法可以单独使用xslt或javascript来实现这一点 我的xslt代码是: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xm
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Report/Scripts">
<html>
<head>
<title>Mobiuss.rtp Test Execution Results</title>
<script type="text/javascript" src="jquery.js"></script>
<style>
.sortable {table-layout: fixed; width:100%; height:25px; border:1px solid #ccc; background-color:#8B7D7B}
.sortable th {padding:4px 6px 6px; background:#444; color:#fff; text-align:center; color:#ccc}
.sortable td {padding:2px 4px 4px; background:#fff; border-bottom:1px solid #ccc;}
.sortable tr {text-overflow:scroll}
.sortable tr:hover {color:#FFB90F}
</style>
</head>
<body>
<xsl:for-each select="Script">
<h1><xsl:value-of select="@File"/></h1>
Execution log
<br>
</br>
<div></div>
<table class="sortable">
<tr>
<th>Time</th>
<th>Position</th>
<th>Type</th>
<th>Message</th>
</tr>
<xsl:for-each select="Message">
<tr>
<td> <xsl:value-of select="@Time"/></td>
<td>Line <xsl:value-of select="@Line"/></td>
<td> <xsl:value-of select="@Type"/></td>
<td> <xsl:value-of select="@Message"/></td>
</tr>
</xsl:for-each>
</table>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Mobiuss.rtp测试执行结果
.可排序{表格布局:固定;宽度:100%;高度:25px;边框:1px实心#ccc;背景色:#8B7D7B}
.sortable th{填充:4px 6px 6px;背景:#444;颜色:#fff;文本对齐:居中;颜色:#ccc}
.sortable td{padding:2px4px4px;background:#fff;border bottom:1px solid#ccc;}
.sortable tr{文本溢出:滚动}
.sortable tr:hover{color:#FFB90F}
执行日志
时间
位置
类型
消息
线
由上述代码形成的表可以在我上面给出的JSFIDLE链接中看到
我的xml文件在这里
<?xml version="1.0" encoding="utf-8"?>
<Report App="RIATest" Version="4.7" Project="D:\Projects\Automation\RIATest\Nomura\Nomura.rtp">
<Startup>
<Message Time="2012-08-30 15:32:38.578" Type="Info" Message="Launching iexplore.exe "http://mobiuss-dev.operasolutions.com:8080/nomura-test/""/>
<Message Time="2012-08-30 15:32:38.625" Type="Info" Message="Application launched (process id=4108)."/>
<Message Time="2012-08-30 15:32:38.625" Type="Info" Message="Waiting for connection from agent..."/>
<Message Time="2012-08-30 15:32:46.453" Type="Info" Message="Agent connection accepted. Application id=nomura-ui, index=0"/>
</Startup>
<Scripts>
<Script File="Login.rts" Time="2012-08-30 15:32:46.468">
<Message Time="2012-08-30 15:32:46.531" Type="Verification" Line="8" Col="58" Message="Verification passed: SparkApplication("nomura-ui")=>visible is equal to true"/>
<Message Time="2012-08-30 15:32:46.578" Type="Verification" Line="10" Col="50" Message="Verification passed: FlexForm("loginForm")=>visible is equal to true"/>
<Message Time="2012-08-30 15:32:46.625" Type="Verification" Line="12" Col="65" Message="Verification passed: FlexLabel("Username::Username:")=>text is equal to "Username:""/>
<Message Time="2012-08-30 15:32:46.656" Type="Verification" Line="14" Col="65" Message="Verification passed: FlexLabel("Password::Password:")=>text is equal to "Password:""/>
<Message Time="2012-08-30 15:32:46.671" Type="Verification" Line="17" Col="39" Message="Verification passed: comp=>label is equal to "Log In""/>
<Message Time="2012-08-30 15:32:46.703" Type="Verification" Line="18" Col="35" Message="Verification passed: comp=>enabled is equal to true"/>
<Message Time="2012-08-30 15:32:46.718" Type="Verification" Line="19" Col="35" Message="Verification passed: comp=>visible is equal to true"/>
<Message Time="2012-08-30 15:32:46.734" Type="Verification" Line="22" Col="35" Message="Verification passed: comp=>enabled is equal to true"/>
<Message Time="2012-08-30 15:32:46.750" Type="Verification" Line="23" Col="54" Message="Verification passed: comp=>label is equal to "Forgot your password?""/>
<Message Time="2012-08-30 15:32:46.765" Type="Verification" Line="24" Col="36" Message="Verification passed: comp=>selected is equal to false"/>
<Message Time="2012-08-30 15:32:46.781" Type="Verification" Line="25" Col="35" Message="Verification passed: comp=>visible is equal to true"/>
<Message Time="2012-08-30 15:32:46.796" Type="Verification" Line="28" Col="61" Message="Verification passed: comp=>text is equal to "CORPORATE BOND SPREAD SIGNAL""/>
<Message Time="2012-08-30 15:32:46.812" Type="Verification" Line="29" Col="35" Message="Verification passed: comp=>visible is equal to true"/>
<Message Time="2012-08-30 15:32:46.906" Type="Action" Line="32" Col="64" Message="SparkTextInput("Username::userName")=>textSelectionChange(0,0)"/>
<Message Time="2012-08-30 15:32:47.000" Type="Action" Line="33" Col="63" Message="SparkTextInput("Username::userName")=>textInput("arun.sekar")"/>
<Message Time="2012-08-30 15:32:47.031" Type="Action" Line="35" Col="61" Message="SparkTextInput("Password::password")=>textInput("opera100")"/>
<Message Time="2012-08-30 15:32:47.093" Type="Action" Line="36" Col="32" Message="SparkButton("Log In")=>click()"/>
</Script>
</Scripts>
<Results>
<Summary scripts="2" time="8.515" errors="2"/>
<Script name="Login.rts" time="0.625" errors="0"/>
<Script name="NOM_0002.rts" time="50.000" errors="2" message="Verification failed: comp=>selected is not equal to expected value true, it is actually equal to false"/>
</Results>
</Report>
您可以在xslt中轻松实现这一点 所有动作类型的示例:
<xsl:value-of select="count(Script/Message[@Type='Action'])"/>
每个表的示例:
<xsl:for-each select="Script">
Table - <xsl:value-of select="position()"/>
<xsl:value-of select="count(Message[@Type='Action'])"/>
</xsl:for-each>
表-
对于行颜色,可以使用以下选项:
<xsl:variable name="Colour">
<xsl:choose>
<xsl:when test="contains(@message,'Verification failed:')">background-color:red;</xsl:when>
<xsl:when test="contains(@message,'Verification passed:')">background-color:green</xsl:when>
<xsl:otherwise> </xsl:otherwise>
</xsl:choose>
</xsl:variable>
<tr style="{$Colour}">
<td> <xsl:value-of select="@Time"/></td>
<td>Line <xsl:value-of select="@Line"/></td>
<td> <xsl:value-of select="@Type"/></td>
<td> <xsl:value-of select="@Message"/></td>
</tr>
背景色:红色;
背景颜色:绿色
线
您可以在xslt中轻松实现这一点
所有动作类型的示例:
<xsl:value-of select="count(Script/Message[@Type='Action'])"/>
每个表的示例:
<xsl:for-each select="Script">
Table - <xsl:value-of select="position()"/>
<xsl:value-of select="count(Message[@Type='Action'])"/>
</xsl:for-each>
表-
对于行颜色,可以使用以下选项:
<xsl:variable name="Colour">
<xsl:choose>
<xsl:when test="contains(@message,'Verification failed:')">background-color:red;</xsl:when>
<xsl:when test="contains(@message,'Verification passed:')">background-color:green</xsl:when>
<xsl:otherwise> </xsl:otherwise>
</xsl:choose>
</xsl:variable>
<tr style="{$Colour}">
<td> <xsl:value-of select="@Time"/></td>
<td>Line <xsl:value-of select="@Line"/></td>
<td> <xsl:value-of select="@Type"/></td>
<td> <xsl:value-of select="@Message"/></td>
</tr>
背景色:红色;
背景颜色:绿色
线
但我希望每个表都有一个,也希望整个表都有一个。例如,它应该显示单词action总共出现了30次,还应该显示单词action在第一个表中出现了10次使用xml文件更新了我的问题,我遇到了另一个问题。正如您在我的代码中看到的,该表具有类“sortable”,我不知道出于某种原因,创建的html文件中的第一个表侦听css,而所有其他表都不遵循css(同一文件中的第一个表除外)。。请帮我解决这个问题谢谢你的解决方案。我觉得这正是我需要的答案。谢谢你花时间理解我的问题并写回解决方案。再次感谢你:)你真是太棒了。。。再一次,你的回答很有魅力:)再次感谢你。(需要更改消息中字母“m”的大小写以获得准确答案)。但是你真的很摇滚,再次感谢你花时间回答我:)但我希望每个表都有,而且作为一个整体。例如,它应该显示单词action总共出现了30次,还应该显示单词action在第一个表中出现了10次用xml文件更新了我的问题,我有另一个问题正如您在我的代码中看到的,该表具有类“sortable”,我不知道出于某种原因,创建的html文件中的第一个表侦听css,而所有其他表都不遵循css(同一文件中的第一个表除外)。。请帮我解决这个问题谢谢你的解决方案。我觉得这正是我需要的答案。谢谢你花时间理解我的问题并写回解决方案。再次感谢你:)你真是太棒了。。。再一次,你的回答很有魅力:)再次感谢你。(需要更改消息中字母“m”的大小写以获得准确答案)。但是你真的很摇滚,再次感谢你花时间回答我:)