【发布时间】:2015-09-03 08:21:51
【问题描述】:
我在关注xslt 文件时遇到了一些问题。
TO TOP 不能很好地工作。它仅在页面顶部有效,但当我向下滚动时,它不会作为链接。
内部链接无法正常工作。它写的文本似乎是链接的,但只有文本被写为链接,它不再起作用了。
您能帮我解决一下吗?
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="5.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="SquishReport/test">
<html>
<head>
<style>
#header {text-align:left;padding:5px;}
#nav {line-height:25px;width:1400px;float:left;padding:5px;}
#section {position:relative;left:20px;top:50px;}
#top {width:200px;position:fixed;top: 60px;right: 5px;}
table, th, td {border: 1px solid black;border-collapse: collapse;}
th, td {padding:2px}
</style>
</head>
<body>
<div id="header">
<h2> Squish-Testauswertung(<xsl:value-of select="epilog/attribute::time"/>)</h2>
</div>
<div id="nav">
<h3>Summary</h3>
<table>
<xsl:for-each select="test">
<xsl:variable name="LinkIt" select="attribute::name"/>
<xsl:choose>
<xsl:when test="descendant::node()/attribute::type='FAIL'">
<tr>
<td bgcolor="red"><a href="#{$LinkIt}" title="click for Information"><xsl:value-of select="$LinkIt"/></a></td>
</tr>
</xsl:when>
<xsl:when test="message/attribute::type='ERROR'">
<tr>
<td bgcolor="yellow"><a href="#{$LinkIt}" title="click for Information"><xsl:value-of select="$LinkIt"/></a></td>
</tr>
</xsl:when>
<xsl:when test="message/attribute::type='FATAL'">
<tr>
<td bgcolor="coral"><a href="#{$LinkIt}" title="click for Information"><xsl:value-of select="$LinkIt"/></a></td>
</tr>
</xsl:when>
<xsl:when test="descendant::node()/attribute::type='PASS'">
<tr>
<td bgcolor="lime"><a href="#{$LinkIt}" title="click for Information"><xsl:value-of select="$LinkIt"/></a></td>
</tr>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</table>
</div>
<div id="top">
<a href="#" title="To the top of this page"><b>TO TOP</b></a>
<br/>
<table>
<tr>
<th></th>
<td>Log</td>
</tr>
<tr>
<th width="20" bgcolor="yellow"></th>
<td>Error</td>
</tr>
<tr>
<th bgcolor="coral"></th>
<td>Fatal</td>
</tr>
<tr>
<th bgcolor="red"></th>
<td>Fail</td>
</tr>
<tr>
<th bgcolor="lime"></th>
<td>Pass</td>
</tr>
</table>
</div>
<div id="section">
<h3>Details</h3>
<table>
<tr bgcolor="Peru">
<th>Testname</th>
<th>Logs</th>
</tr>
<xsl:for-each select="test">
<xsl:variable name="LogNum" select="count(message)" />
<xsl:variable name="VerifNum" select="count(verification)"/>
<xsl:variable name="LinkName" select="attribute::name"/>
<tr>
<th rowspan="{$LogNum+$VerifNum+1}" style="text-align:left;vertical-align:top;position:"><a name="#{$LinkName}"><xsl:value-of select="$LinkName"/></a></th>
</tr>
<xsl:for-each select="descendant::node()">
<xsl:choose>
<xsl:when test="attribute::type='LOG'">
<tr>
<td><xsl:value-of select="description"/></td>
</tr>
</xsl:when>
<xsl:when test="attribute::type='FATAL'">
<tr>
<td bgcolor="coral"><xsl:value-of select="description"/></td>
</tr>
</xsl:when>
<xsl:when test="attribute::type='ERROR'">
<tr>
<td bgcolor="yellow"><xsl:value-of select="description"/></td>
</tr>
</xsl:when>
<xsl:when test="attribute::type='FAIL'">
<tr>
<td bgcolor="red"><xsl:value-of select="description"/></td>
</tr>
</xsl:when>
<xsl:when test="attribute::type='PASS'">
<tr>
<td bgcolor="lime"><xsl:value-of select="description"/></td>
</tr>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:for-each>
</table>
</div>
</body>
</html>
</xsl:template>
【问题讨论】:
-
如果没有可验证的示例,很难理解您的意思。您展示了您的代码是一件好事,但是要运行它并测试它,我们还需要一个(最少的!)输入 XML 文档来显示这种错误行为。如果您需要有关设置的建议,请查看 SO 的帮助页面 minimal reproducible example。
-
我认为与其说是 XSLT 问题,不如说是 HTML 问题。在您尝试编写 XSLT 之前,您应该首先知道您想要什么输出。因此,如果您是在文本编辑器中亲手编写 HTML,您需要确定 HTML 的外观。如果您在 HTML 方面遇到困难,请先看看这个问题:stackoverflow.com/questions/32370867/…。
-
这里有几个提示: (1) 不要在匹配表达式中写
attribute::name,你可以只写@name。 (2) 用*/@type代替descendant::node()/attribute::type。还请提供一个简单的示例输入文档和预期的输出。 -
@SeanB.Durkin:
descendant::node()不与*相同,即child::*,即child::element()。在这种情况下,您可以使用*,因为只有元素节点具有属性,但您不能将descendant替换为child轴(当然,除非一开始并不意味着后代轴)。 -
@Abel 总的来说,你是对的,但在他使用它的特定位置,我对他的意图做出了假设。我可能是错的,但我不认为他真的打算
decendant::。 OP 需要用一些测试用例来澄清。
标签: html css xml xslt xslt-1.0