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

Re: Getting equivalence classes on attributes

Subject: Re: Getting equivalence classes on attributes
From: Francis Norton <francis@xxxxxxxxxxx>
Date: Mon, 18 Jun 2001 07:00:38 +0100
equivalence class
"Rafael R. Sevilla" wrote:
> 
> Hello.  Is there a way to write an XPath expression that will return each
> equivalence class on the value of an attribute, i.e. every collection of
> nodes whose value for a certain attribute are the same e.g.
> 
See http://www.jenitennison.com/xslt/grouping/muenchian.html for the
general method of grouping elements by some XPath key expression. You
would want to group attributes with something like: 

<xsl:key name="attributes-by-name-and-value" match="@*"
use="concat(name(), '=', ." />

with, instead of a xsl:value-of, something like:

<xsl:copy-of select=".." />

In other words,

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:output indent="yes"/>
   <xsl:key name="all-attributes" match="@*" use="concat(name(), '=',
.)"/>
   <xsl:template match="/">
      <groups>
         <xsl:for-each select="//@*[generate-id() =
generate-id(key('all-attributes', concat(name(), '=', .))[1]) ]">
            <xsl:sort select="name()"/>
            <group attribute="{name()}" value="{.}>
               <xsl:for-each select="key('all-attributes',
concat(name(), '=', .))">
                  <xsl:copy-of select=".."/>
               </xsl:for-each>
            </group>
         </xsl:for-each>
      </groups>
   </xsl:template>
</xsl:stylesheet>

This works with both saxon and msxsl. 

Francis.

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.