Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Complex navigation

Reply
Thread Tools

Complex navigation

 
 
Fabien Bergeret
Guest
Posts: n/a
 
      04-26-2005
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\sourc e\fr\mplusx\commun\domaine\donnees\bancaires\Agenc e.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.met rics.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.met rics.ClassFanOutComplexityCheck"/>
</file>
<file name="C:\java\analyses\moca\sources\Services\sourc e\fr\mplusx\commun\domaine\donnees\bancaires\Agenc eFactory.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.met rics.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.met rics.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.met rics.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.met rics.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.met rics.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">
<xslaram 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>
<xsltherwise>
'false'
</xsltherwise>
</xsl:choose>
</xsl:template>

This code is awfully slow on big files (>10Mo) ; any ideas to optimize
?
Thanks.
 
Reply With Quote
 
 
 
 
David Carlisle
Guest
Posts: n/a
 
      04-26-2005

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
 
Reply With Quote
 
 
 
 
Fabien Bergeret
Guest
Posts: n/a
 
      04-27-2005
Thanks, David, it worked perfectly well.
And thanks for having learnt me the "key" trick : very useful and very
powerful ...

David Carlisle wrote:
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How complex is complex? Kottiyath Python 22 03-28-2009 10:11 PM
Disable the navigation buttons for IE navigation toolbar Laurahn ASP .Net 3 02-06-2007 04:17 AM
wsdl2java: method parameter a complex type that extends another complex type Robert Mark Bram Java 0 02-04-2007 10:06 AM
[XML Schema] Content type of complex type definition with complex content Stanimir Stamenkov XML 2 10-25-2005 10:16 AM
For expert on complex loops (reposted) - complex looping problem news.amnet.net.au Java 1 04-13-2004 07:10 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57