Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
155 views
in Technique[技术] by (71.8m points)

html - Internal link in xslt does not work

I have some problem regarding following xslt file.

  1. TO TOP does not work very well. It work only on top of page but when I am scrolling down then it is going not to be as a link.

  2. internal Link does not work properly. It writes the the text as seems to be linked but only the text is written as a link and it does not work anymore.

Can you please help me how can I fix them?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I have assumed that you are using Squishy format version 3, and that your test cases are not nested.

If your input document is, for example, ...

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

... then this XSLT 1.0 stylesheet ...

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

... will yield a result like this ....

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...