Fix cpd xslt sample templates

This commit is contained in:
Andreas Dangel 2024-06-23 21:03:12 +02:00
parent 33f9268cf7
commit 40bd882f3e
No known key found for this signature in database
GPG Key ID: 93450DF2DF9A3FA3
3 changed files with 30 additions and 21 deletions

View File

@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xpath-default-namespace="https://pmd-code.org/schema/cpd-report">
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:cpd="https://pmd-code.org/schema/cpd-report"
exclude-result-prefixes="cpd">
<!--
PMD CPD (Copy and Paste Detector) XML to HTML transformer
-->
@ -68,10 +70,10 @@
<th>Approximate number of bytes</th>
</tr>
<tr>
<td class="SummaryNumber"><xsl:value-of select="count(//duplication)"/></td>
<td class="SummaryNumber"><xsl:value-of select="sum(//duplication/@lines)"/></td>
<td class="SummaryNumber"><xsl:value-of select="sum(//duplication/@tokens)"/></td>
<td class="SummaryNumber"><xsl:value-of select="sum(//duplication/@tokens) * 4"/></td>
<td class="SummaryNumber"><xsl:value-of select="count(//cpd:duplication)"/></td>
<td class="SummaryNumber"><xsl:value-of select="sum(//cpd:duplication/@lines)"/></td>
<td class="SummaryNumber"><xsl:value-of select="sum(//cpd:duplication/@tokens)"/></td>
<td class="SummaryNumber"><xsl:value-of select="sum(//cpd:duplication/@tokens) * 4"/></td>
</tr>
</table>
</div>
@ -91,7 +93,7 @@
</tr>
</thead>
<tbody>
<xsl:apply-templates select="pmd-cpd/duplication" />
<xsl:apply-templates select="cpd:pmd-cpd/cpd:duplication" />
</tbody>
</table>
</div>
@ -133,7 +135,7 @@
</xsl:template>
<!-- templates -->
<xsl:template match="pmd-cpd/duplication">
<xsl:template match="cpd:pmd-cpd/cpd:duplication">
<xsl:for-each select=".">
<tr>
<td><xsl:value-of select="@lines"/></td>
@ -141,7 +143,7 @@
<td>
<table class="table table-light table-bordered table-striped table-hover">
<tr><th>column</th><th>endcolumn</th><th>line</th><th>endline</th><th>path</th></tr>
<xsl:for-each select="file">
<xsl:for-each select="cpd:file">
<tr>
<td><xsl:value-of select="@column"/></td>
<td><xsl:value-of select="@endcolumn"/></td>
@ -152,7 +154,7 @@
</xsl:for-each>
</table>
</td>
<td><pre><xsl:value-of select="codefragment"/></pre></td>
<td><pre><xsl:value-of select="cpd:codefragment"/></pre></td>
</tr>
</xsl:for-each>
</xsl:template>

View File

@ -1,11 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Stylesheet to turn the XML output of CPD into a nice-looking HTML page -->
<!-- $Id$ -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xpath-default-namespace="https://pmd-code.org/schema/cpd-report" version="2.0">
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:cpd="https://pmd-code.org/schema/cpd-report"
exclude-result-prefixes="cpd" version="2.0">
<xsl:output method="html" encoding="utf-8" doctype-system="about:legacy-compat"/>
<xsl:param name="lines" required="yes">30</xsl:param>
<xsl:template match="pmd-cpd">
<xsl:template match="cpd:pmd-cpd">
<html>
<head>
<meta charset="utf-8"/>
@ -46,10 +48,10 @@
<th>Approx # bytes</th>
</tr>
<tr>
<td class="SummaryNumber"><xsl:value-of select="count(//duplication[@lines>$lines])"/></td>
<td class="SummaryNumber"><xsl:value-of select="sum(//duplication[@lines>$lines]/@lines)"/></td>
<td class="SummaryNumber"><xsl:value-of select="sum(//duplication[@lines>$lines]/@tokens)"/></td>
<td class="SummaryNumber"><xsl:value-of select="sum(//duplication[@lines>$lines]/@tokens) * 4"/></td>
<td class="SummaryNumber"><xsl:value-of select="count(//cpd:duplication[@lines>$lines])"/></td>
<td class="SummaryNumber"><xsl:value-of select="sum(//cpd:duplication[@lines>$lines]/@lines)"/></td>
<td class="SummaryNumber"><xsl:value-of select="sum(//cpd:duplication[@lines>$lines]/@tokens)"/></td>
<td class="SummaryNumber"><xsl:value-of select="sum(//cpd:duplication[@lines>$lines]/@tokens) * 4"/></td>
</tr>
</table>
<p/>
@ -58,13 +60,13 @@
<p/>
<table>
<tr style="background-color: #444444; color: #DDDDDD;"><td>ID</td><td>Files</td><td>Lines</td></tr>
<xsl:for-each select="//duplication[@lines>$lines]">
<xsl:for-each select="//cpd:duplication[@lines>$lines]">
<xsl:sort data-type="number" order="descending" select="@lines"/>
<tr>
<td class="ItemNumber"><xsl:value-of select="position()"/></td>
<td>
<table>
<xsl:for-each select="file">
<xsl:for-each select="cpd:file">
<tr><td><a><xsl:attribute name="href">../src/<xsl:value-of select="@path"/>.html#<xsl:value-of select="@line"/></xsl:attribute><xsl:value-of select="@path"/></a></td><td> line <xsl:value-of select="@line"/></td></tr>
</xsl:for-each>
</table>
@ -82,7 +84,7 @@
<textarea cols="100" wrap="off" class='CodeFragment' style='display:none;'>
<xsl:attribute name="rows"><xsl:value-of select="$lines"/></xsl:attribute>
<xsl:attribute name="id">frag_<xsl:value-of select="position()"/></xsl:attribute>
<xsl:value-of select="codefragment"/>
<xsl:value-of select="cpd:codefragment"/>
</textarea>
</td>
</tr></table>

View File

@ -1,8 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<pmd-cpd>
<pmd-cpd xmlns="https://pmd-code.org/schema/cpd-report"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
pmdVersion="7.3.0"
timestamp="2024-06-23T09:00:00+02:00"
version="1.0.0"
xsi:schemaLocation="https://pmd-code.org/schema/cpd-report https://pmd.github.io/schema/cpd-report_1_0_0.xsd">
<duplication lines="60" tokens="75">
<file column="2" endcolumn="3" endline="6" line="1" path="/var/Foo.java"/>
<file column="4" endcolumn="5" endline="78" line="73" path="/var/Foo.java"/>
<file column="2" endcolumn="3" endline="6" line="1" begintoken="0" endtoken="1" path="/var/Foo.java"/>
<file column="4" endcolumn="5" endline="78" line="73" begintoken="0" endtoken="1" path="/var/Foo.java"/>
<codefragment><![CDATA[code
fragment]]></codefragment>
</duplication>