Complex navigation

Discussion in 'XML' started by Fabien Bergeret, Apr 26, 2005.

  1. 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.
     
    Fabien Bergeret, Apr 26, 2005
    #1
    1. Advertising

  2. 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
     
    David Carlisle, Apr 26, 2005
    #2
    1. Advertising

  3. 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
     
    Fabien Bergeret, Apr 27, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. news.amnet.net.au
    Replies:
    1
    Views:
    581
    =?UTF-8?b?TMSByrtpZSBUZWNoaWU=?=
    Apr 13, 2004
  2. Stanimir Stamenkov
    Replies:
    2
    Views:
    749
    Stanimir Stamenkov
    Oct 25, 2005
  3. Laurahn
    Replies:
    3
    Views:
    910
    Steven Cheng[MSFT]
    Feb 6, 2007
  4. Robert Mark Bram
    Replies:
    0
    Views:
    686
    Robert Mark Bram
    Feb 4, 2007
  5. Kottiyath

    How complex is complex?

    Kottiyath, Mar 18, 2009, in forum: Python
    Replies:
    22
    Views:
    769
Loading...

Share This Page