[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Unique attribute values

Subject: Re: Unique attribute values
From: "Andrew Welch" <andrew.j.welch@xxxxxxxxx>
Date: Thu, 10 Jan 2008 16:41:29 +0000
Re:  Unique attribute values
On 10/01/2008, Sean Tiley <sean.tiley@xxxxxxxxx> wrote:
> Hi there,
> I have the following structure in an XML file
>
> <root>
>  <file name="c:\test.java">
>   <error line="4" message="Message1" severity="2"/>
>   <error line="67" message="Message2" severity="4"/>
>  </file>
>   <file name="c:\code.java">
>   <error line="2" message="Message1" severity="2"/>
>   <error line="54" message="Message2" severity="4"/>
>   <error line="122" message="Message1" severity="2"/>
>   <error line="124" message="Message2" severity="4"/>
>  </file>
> </root>
>
> What I want to do is the following.
> I want a list of the unique values for the message attribute
> I then want to output attribute value and the number of times it
> appears in the file.
>
> I can successfully get the count for an attribute value by using
> <xsl:value-of select="count(/root/file/error[@message='Message1'])"/>
> but I am hardcoding the 'Message1" which is clearly not optimal

Assuming XSLT 2.0,

<xsl:for-each-group select="/root/file/error" group-by="@message">
  <xsl:value-of select="current-grouping-key()"/>
  <xsl:value-of select="count(current-group())"/>
</

you'll need to sort out the formatting...


-- 
Andrew Welch
http://andrewjwelch.com
Kernow: http://kernowforsaxon.sf.net/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.