Complex navigation

F

Fabien Bergeret

Here is sample of an XML I try to parse :
<?xml version="1.0" encoding="UTF-8"?>
<checkstyle version="3.5">
<file name="C:\java\analyses\moca\sources\Services\source\fr\mplusx\commun\domaine\donnees\bancaires\Agence.java">
<error line="37" column="1" severity="info" message="Le DAC (Data
Abstraction Coupling) de la classe est de 15 alors que le maximum
autorisé est de 7."
source="com.puppycrawl.tools.checkstyle.checks.metrics.ClassDataAbstractionCouplingCheck"/>
<error line="37" column="1" severity="info" message="Le Fan-Out
Complexity de la classe est de 29 alors que le maximum autorisé est
de 20." source="com.puppycrawl.tools.checkstyle.checks.metrics.ClassFanOutComplexityCheck"/>
</file>
<file name="C:\java\analyses\moca\sources\Services\source\fr\mplusx\commun\domaine\donnees\bancaires\AgenceFactory.java">
<error line="47" column="1" severity="info" message="Le DAC (Data
Abstraction Coupling) de la classe est de 10 alors que le maximum
autorisé est de 7."
source="com.puppycrawl.tools.checkstyle.checks.metrics.ClassDataAbstractionCouplingCheck"/>
<error line="47" column="1" severity="info" message="Le Fan-Out
Complexity de la classe est de 24 alors que le maximum autorisé est
de 20." source="com.puppycrawl.tools.checkstyle.checks.metrics.ClassFanOutComplexityCheck"/>
<error line="157" column="9" severity="info" message="La métrique
NCSS pour cette méthode vaut 56 alors que le maximum autorisé est de
50." source="com.puppycrawl.tools.checkstyle.checks.metrics.JavaNCSSCheck"/>
<error line="247" column="9" severity="info" message="La métrique
NCSS pour cette méthode vaut 53 alors que le maximum autorisé est de
50." source="com.puppycrawl.tools.checkstyle.checks.metrics.JavaNCSSCheck"/>
<error line="335" column="9" severity="info" message="La complexité
cyclomatique de la classe est de 11 alors que le maximum autorisé est
de 10." source="com.puppycrawl.tools.checkstyle.checks.metrics.CyclomaticComplexityCheck"/>
</file>
</checkstyle>

What I try to do is to count, for each file/error/source, the number
of times the source exists.
Here is the code sample I currently use :
<xsl:for-each select="file/error">
<xsl:variable name="first">
<xsl:call-template name="isfirst">
<xsl:with-param name="source" select="@source"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="source" select="@source" />
<xsl:if test="$first = 'true'">
<tr><xsl:call-template name="alternated-row"/>
<td nowrap="nowrap"><xsl:value-of select="@source"/></td>
<td><xsl:value-of
select="count(file/error[@source=$source])"/></td>
</tr>
</xsl:if>
</xsl:for-each>
<xsl:template name="isfirst">
<xsl:param name="source"/>
<xsl:choose>
<xsl:when test="count(preceding-sibling::*[@source = $source])=0">
<xsl:value-of select="count(parent::*/preceding-sibling::*/error[@source
= $source])=0"/>
</xsl:when>
<xsl:eek:therwise>
'false'
</xsl:eek:therwise>
</xsl:choose>
</xsl:template>

This code is awfully slow on big files (>10Mo) ; any ideas to optimize
?
Thanks.
 
D

David Carlisle

define a key

<xsl:key name="s" match="error" use="@source"/>

then you can tell if this is the first error with that source by going

test="generate-id()=generate-id(key('s',@source))"

and you can find out how many errors have this source with

select="count(key('s',@source))"

This may well give orders of magnitude speed improvements over
searching every time along preceding-sibling, at the cost of the space
required to build the key index.

David
 
F

Fabien Bergeret

Thanks, David, it worked perfectly well.
And thanks for having learnt me the "key" trick : very useful and very
powerful ...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,246
Members
46,841
Latest member
WilmerBelg

Latest Threads

Top