xslt中的内部链接不起作用

时间:2015-09-03 08:21:52

标签: html css xml xslt xslt-1.0

关于xslt文件,我遇到了一些问题。

  1. TO TOP效果不佳。它只在页面上工作,但当我向下滚动时,它不会作为链接。

  2. 内部链接无法正常工作。它将文本写成似乎是链接的,但只有文本被写为链接,它不再起作用。

  3. 你能帮我解决一下如何解决这些问题吗?

    <?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>
    

1 个答案:

答案 0 :(得分:1)

我假设您正在使用Squishy format version 3,并且您的测试用例未嵌套。

例如,如果您的输入文档是......

<SquishReport xmlns="http://www.froglogic.com/resources/schemas/xml3" version="3">
  <test type="testsuite">
    <prolog time="2015-06-19T11:22:27+02:00">
      <name>My test suite</name>
    </prolog>

  <test type="testcase">
    <prolog time="2015-06-19T11:22:27+02:00">
        <name>Test case 1</name>
        <location>
          <uri>http://www.abc.net.au</uri>
        </location>
      </prolog>
    <verification>
        <location>
          <uri>x-testcase:/unit1.pas</uri>
          <lineNo>2</lineNo>
        </location>
    <scriptedVerificationResult time="2015-06-19T11:22:27+02:01" type="PASS">
      <text>Summed a column of numbers</text>
      <detail>The sum was correct</detail>
    </scriptedVerificationResult>  
    </verification>
    <verification>
        <location>
          <uri>x-testcase:/unit1.pas</uri>
          <lineNo>6</lineNo>
        </location>
    <propertyVerificationResult time="2015-06-19T11:22:27+02:01" type="PASS" />
    </verification>
    <verification>
        <location>
          <uri>x-testcase:/unit2.pas</uri>
          <lineNo>3</lineNo>
        </location>
    <screenshotVerificationResult time="2015-06-19T11:22:27+02:02" type="ERROR" />
    </verification>
    <message time="2015-06-19T11:22:27+02:03" type="LOG">This is a log message</message>
    <message time="2015-06-19T11:22:27+02:04" type="WARNING">This is a warning</message>
    <message time="2015-06-19T11:22:27+02:05" type="FATAL">Fatality!</message>
    <epilog time="2015-06-19T11:22:27+02:06"/>
  </test>

  <test type="testcase">
    <prolog time="2015-06-19T11:22:27+02:07">
        <name>Test case 2</name>
        <location>
          <uri>http://feedly.com</uri>
        </location>
      </prolog>
    <verification>
        <location>
          <uri>x-testcase:/unit2.pas</uri>
          <lineNo>5</lineNo>
        </location>
    <scriptedVerificationResult time="2015-06-19T11:22:27+02:08" type="FAIL">
      <text>Something went wrong</text>
      <detail>Stack overflow</detail>
    </scriptedVerificationResult>  
    </verification>
    <epilog time="2015-06-19T11:22:27+02:09"/>
  </test>


  <epilog time="2015-06-19T11:22:27+02:10"/>
  </test>
</SquishReport>

...然后是这个XSLT 1.0样式表......

<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:sq="http://www.froglogic.com/resources/schemas/xml3"
  version="1.0"
  exclude-result-prefixes="sq">  

<xsl:output method="html" version="5.0" encoding="UTF-8" indent="yes"/>

<xsl:template match="sq:test" mode="summary">
  <xsl:apply-templates select="
    (sq:verification/sq:scriptedVerificationResult  [@type='FAIL'] |
     sq:verification/sq:screenshotVerificationResult[@type='FAIL'] |
     sq:verification/sq:propertyVerificationResult  [@type='FAIL'] |
     sq:verification/sq:tableVerificationResult     [@type='FAIL'] 
     )[1]" mode="summary" />
  <xsl:apply-templates select="
    (sq:verification/sq:scriptedVerificationResult  [@type='FATAL'] |
     sq:verification/sq:screenshotVerificationResult[@type='FATAL'] |
     sq:verification/sq:propertyVerificationResult  [@type='FATAL'] |
     sq:verification/sq:tableVerificationResult     [@type='FATAL'] | 
     sq:message                                     [@type='FATAL'] 
     )[1]" mode="summary" />
  <xsl:apply-templates select="
    (sq:verification/sq:scriptedVerificationResult  [@type='ERROR'] |
     sq:verification/sq:screenshotVerificationResult[@type='ERROR'] |
     sq:verification/sq:propertyVerificationResult  [@type='ERROR'] |
     sq:verification/sq:tableVerificationResult     [@type='ERROR'] 
     )[1]" mode="summary" />
  <xsl:apply-templates select="
    (sq:verification/sq:scriptedVerificationResult  [@type='PASS'] |
     sq:verification/sq:screenshotVerificationResult[@type='PASS'] |
     sq:verification/sq:propertyVerificationResult  [@type='PASS'] |
     sq:verification/sq:tableVerificationResult     [@type='PASS'] 
     )[1]" mode="summary" />
  <xsl:apply-templates select="sq:message[@type='WARNING'][1]" mode="summary" />
</xsl:template>

<xsl:template match="@type">
    <xsl:attribute name="bgcolor">
      <xsl:choose>
        <xsl:when test=".='FAIL'"   >red</xsl:when>
        <xsl:when test=".='FATAL'"  >coral</xsl:when>
        <xsl:when test=".='ERROR'"  >yellow</xsl:when>
        <xsl:when test=".='PASS'"   >lime</xsl:when>
        <xsl:when test=".='WARNING'">amber</xsl:when>
      </xsl:choose>
    </xsl:attribute>  
</xsl:template>



<xsl:template match="sq:scriptedVerificationResult   |
                     sq:screenshotVerificationResult |
                     sq:propertyVerificationResult   |
                     sq:tableVerificationResult      |
                     sq:message" mode="summary">
  <tr><td>
    <xsl:apply-templates select="@type" />
    <a href="{
      self::node()[not(self::sq:message)]/../../sq:prolog/sq:location/sq:uri/text() |
      self::sq:message/../sq:prolog/sq:location/sq:uri/text() 
    }" title="click for Information">
      <xsl:value-of select="
        self::node()[not(self::sq:message)]/../../sq:prolog/sq:name |
        self::sq:message/../sq:prolog/sq:name
      " />
    </a>
  </td></tr>                                 
</xsl:template>

<xsl:template match="/">
  <html>
  <head>
    <title>Squish-Testauswertung</title>
  </head> 
  <body>
<div id="header">
<h2>Squish-Testauswertung(2015-06-19T11:22:27+02:00)</h2>
</div>
<div id="nav">
  <h3>Summary</h3>
  <table>
    <xsl:apply-templates select="sq:SquishReport/sq:test/sq:test[@type='testcase']" mode="summary" />
  </table>
</div>   

<div id="top">
  <br/>
  <table>
    <tr><th width="20" >&#160;</th> <td>Log</td></tr>
    <tr><th bgcolor="yellow"></th><td>Error</td></tr>
    <tr><th bgcolor="coral"></th><td>Fatal</td></tr>
    <tr><th bgcolor="amber"></th><td>Warning</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:apply-templates select="sq:SquishReport/sq:test/sq:test[@type='testcase']" />
   </table>
</div>
<br/>
<a href="#header" title="To the top of this page"><b>TO TOP</b></a>

</body>  
</html>  
</xsl:template>

<xsl:template match="sq:test">
  <tr><th
        rowspan="{count( sq:verification | sq:message) + 1}"
        style="text-align:left;vertical-align:top;position:">
    <a>
      <xsl:attribute name="name">
        <xsl:value-of select="sq:prolog/sq:location/sq:uri" />
      </xsl:attribute>  
      <xsl:value-of select="sq:prolog/sq:name" />
    </a></th></tr>
  <xsl:apply-templates select="sq:verification | sq:message" />
</xsl:template>

<xsl:template match="sq:verification[sq:scriptedVerificationResult]">
   <tr><td>
     <xsl:apply-templates select="sq:scriptedVerificationResult/@type" />
     <xsl:value-of select="sq:scriptedVerificationResult/sq:detail" />
   </td></tr>
</xsl:template>

<xsl:template match="sq:verification[sq:screenshotVerificationResult]">
   <tr><td>
     <xsl:apply-templates select="sq:screenshotVerificationResult/@type" />
     <xsl:text>screenshotVerificationResult</xsl:text>
   </td></tr>
</xsl:template>

<xsl:template match="sq:verification[sq:propertyVerificationResult]">
   <tr><td>
     <xsl:apply-templates select="sq:propertyVerificationResult/@type" />
     <xsl:text>propertyVerificationResult</xsl:text>
   </td></tr>
</xsl:template>

<xsl:template match="sq:verification[sq:tableVerificationResult]">
   <tr><td>
     <xsl:apply-templates select="sq:tableVerificationResult/@type" />
     <xsl:text>tableVerificationResult</xsl:text>
   </td></tr>
</xsl:template>

<xsl:template match="sq:message">
   <tr><td>
     <xsl:apply-templates select="@type" />
     <xsl:value-of select="text()" />
   </td></tr>
</xsl:template>

</xsl:stylesheet>

...会产生这样的结果......

#header {text-align:left;padding:5px;}
#nav {line-height:25px;width:1400px;float:left;padding:5px;}
#section {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}
<div id="header">
      <h2>Squish-Testauswertung(2015-06-19T11:22:27+02:00)</h2>
    </div>
    <div id="nav">
      <h3>Summary</h3>
      <table>
        <tr>
          <td bgcolor="coral"><a href="http://www.abc.net.au" title="click for Information">Test case 1</a></td>
        </tr>
        <tr>
          <td bgcolor="yellow"><a href="http://www.abc.net.au" title="click for Information">Test case 1</a></td>
        </tr>
        <tr>
          <td bgcolor="lime"><a href="http://www.abc.net.au" title="click for Information">Test case 1</a></td>
        </tr>
        <tr>
          <td bgcolor="amber"><a href="http://www.abc.net.au" title="click for Information">Test case 1</a></td>
        </tr>
        <tr>
          <td bgcolor="red"><a href="http://feedly.com" title="click for Information">Test case 2</a></td>
        </tr>
      </table>
    </div>
    <div id="top"><br><table>
        <tr>
          <th width="20"> </th>
          <td>Log</td>
        </tr>
        <tr>
          <th bgcolor="yellow"></th>
          <td>Error</td>
        </tr>
        <tr>
          <th bgcolor="coral"></th>
          <td>Fatal</td>
        </tr>
        <tr>
          <th bgcolor="amber"></th>
          <td>Warning</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>
        <tr>
          <th rowspan="7" style="text-align:left;vertical-align:top;position:"><a name="http://www.abc.net.au">Test case 1</a></th>
        </tr>
        <tr>
          <td bgcolor="lime">The sum was correct</td>
        </tr>
        <tr>
          <td bgcolor="lime">propertyVerificationResult</td>
        </tr>
        <tr>
          <td bgcolor="yellow">screenshotVerificationResult</td>
        </tr>
        <tr>
          <td bgcolor="">This is a log message</td>
        </tr>
        <tr>
          <td bgcolor="amber">This is a warning</td>
        </tr>
        <tr>
          <td bgcolor="coral">Fatality!</td>
        </tr>
        <tr>
          <th rowspan="2" style="text-align:left;vertical-align:top;position:"><a name="http://feedly.com">Test case 2</a></th>
        </tr>
        <tr>
          <td bgcolor="red">Stack overflow</td>
        </tr>
      </table>
    </div><br><a href="#header" title="To the top of this page"><b>TO TOP</b></a></body>

相关问题