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

RE: Count of unique attribute names

Subject: RE: Count of unique attribute names
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 3 Nov 2006 13:01:38 -0000
unique attribute
> My XSLT 2.0 solution below is working. I am just wondering if 
> there is an easier way that could perhaps bring 
> distinct-values() into play?
> 
> <xsl:variable name="uniqueAttributeNames">
> 	<xsl:for-each-group select="//@*" group-by="local-name()">
> 		<xsl:sequence select="local-name()"/>
>       </xsl:for-each-group>
> </xsl:variable>
> <xsl:sequence 
> select="string-length(replace(replace($uniqueAttributeNames,
> '\c+',  'x'), '\C+', ''))"/>
> 

Firstly, if you make uniqueAttributeNames hold a sequence of strings rather
than a single string, then you can use the much simpler expression
count($uniqueAttributeNames) to count them.

You can do this (a) by adding an "as" clause to the variable declaration

<xsl:variable name="uniqueAttributeNames" as="xs:string*">

or (b) by using distinct-values. So the whole thing is just

<xsl:sequence select="count(distinct-values(//@*/local-name()))"/>

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-2007 All Rights Reserved.