XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
David CorleySubject: Counting unique values of an attribute based on an existing attiribute group
Author: David Corley
Date: 15 Nov 2006 04:40 AM
My xml document format is as follows:
<file name="nms\arne\client\entries\AreaInputEntry.java">
<violation line="36" rule="ImmutableField" ruleset="Design Rules" package="nms.arne.client.entries" class="AreaInputEntry" externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#ImmutableField" priority="5">
Private field 'gridbag' could be made final; it is only initialized in the declaration or constructor.
</violation>
<violation line="37" rule="ImmutableField" ruleset="Design Rules" package="nms.arne.client.entries" class="AreaInputEntry" externalInfoUrl="http://pmd.sourceforge.net/rules/design.html#ImmutableField" priority="5">
Private field 'constraints' could be made final; it is only initialized in the declaration or constructor.
</violation>
<violation line="50" rule="MethodArgumentCouldBeFinal" ruleset="Optimization Rules" package="nms.arne.client.entries" class="AreaInputEntry" method="init" externalInfoUrl="http://pmd.sourceforge.net/rules/optimizations.html#MethodArgumentCouldBeFinal" priority="4">
Parameter 'any' is not assigned and could be declared final
</violation>
<violation line="57" rule="LocalVariableCouldBeFinal" ruleset="Optimization Rules" package="nms.arne.client.entries" class="AreaInputEntry" method="init" externalInfoUrl="http://pmd.sourceforge.net/rules/optimizations.html#LocalVariableCouldBeFinal" priority="4">
Local variable could be declared final
</violation>
<violation line="58" rule="LocalVariableCouldBeFinal" ruleset="Optimization Rules" package="nms.arne.client.entries" class="AreaInputEntry" method="init" externalInfoUrl="http://pmd.sourceforge.net/rules/optimizations.html#LocalVariableCouldBeFinal" priority="4">
Local variable could be declared final
</violation>
<violation line="60" rule="AvoidInstantiatingObjectsInLoops" ruleset="Optimization Rules" package="nms.arne.client.entries" class="AreaInputEntry" method="init" externalInfoUrl="http://pmd.sourceforge.net/rules/optimizations.html#AvoidInstantiatingObjectsInLoops" priority="6">
Avoid instantiating new objects inside loops
</violation>
<violation line="121" rule="MethodArgumentCouldBeFinal" ruleset="Optimization Rules" package="nms.arne.client.entries" class="SummaryLabel" method="replaceTag" externalInfoUrl="http://pmd.sourceforge.net/rules/optimizations.html#MethodArgumentCouldBeFinal" priority="4">
Parameter 'replacement' is not assigned and could be declared final
</violation>
<violation line="121" rule="MethodArgumentCouldBeFinal" ruleset="Optimization Rules" package="nms.arne.client.entries" class="SummaryLabel" method="replaceTag" externalInfoUrl="http://pmd.sourceforge.net/rules/optimizations.html#MethodArgumentCouldBeFinal" priority="4">
Parameter 'tag' is not assigned and could be declared final
</violation>
<violation line="123" rule="LocalVariableCouldBeFinal" ruleset="Optimization Rules" package="nms.arne.client.entries" class="SummaryLabel" method="replaceTag" externalInfoUrl="http://pmd.sourceforge.net/rules/optimizations.html#LocalVariableCouldBeFinal" priority="4">
Local variable could be declared final
</violation>
</file>

I've grouped the violations together through the use of the following:
<xsl:for-each-group select=" //violation" group-by="@package">
Now I want to count the unique instances of each class attribute where the package attribute is equal to the current-grouping-key.

I've tried the following but it doesn't work:

<xsl:value-of select="count(distinct-values(//@class[@package=current-grouping-key()]))"/>

Can anyone help me? I'm using xslt 2.0.

Postnext
James DurningSubject: Counting unique values of an attribute based on an existing attiribute group
Author: James Durning
Date: 15 Nov 2006 04:06 PM
Originally Posted: 15 Nov 2006 01:39 PM
Would this work for you?
<xsl:value-of select="count(distinct-values(current-group()/@class))"/>

--EDITED to use current-group()

Posttop
David CorleySubject: Counting unique values of an attribute based on an existing attiribute group
Author: David Corley
Date: 16 Nov 2006 09:59 AM
I figured out the same answer later that evening, but thanks for the reply! You were correct!

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.