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

RE: Selecting all repeated elements

Subject: RE: Selecting all repeated elements
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 7 Jul 2006 19:52:11 +0100
jason elemen
> I've been hunting for an elegant way to obtain a sequence 
> containing those elements that share a common attribute (in 
> this case <course> elements with the same "code" attribute. 

That doesn't sound like a sequence to me, it sounds like a set of sequences,
one for each attribute value.

Anyway, this sounds like a standard description of the grouping problem, and
the first thing you should do is look at xsl:for-each-group if you are using
XSLT 2.0, or Muenchian grouping in the case of 1.0 (see
http://www.jenitennison.com/xslt/grouping)

Michael Kay
http://www.saxonica.com/

 
> I think that I've got a kludged solution using <xsl:for-each> 
> as follows:
> 
> <xsl:for-each select="child::course">
>    <xsl:variable name="targetCode" select="attribute::code"/>
>    <xsl:variable name="duplicates">
>      <if test="count(/descendant::course[attribute::code =
> $targetCode]) > 1">
>        <xsl:value-of select="concat(attribute::code,ancestor::term/
> attribute::name, ' ')"/>
>      </xsl:if>
>    </xsl:variable>
> </xsl:for-each>
> 
> This is ugly, and the result isn't a nodeset, so in general 
> I'm not impressed.  The thing I haven't been able to figure 
> out is whether XPath has something equivalent to a RegExp 
> backreference, which would allow something like:
> 
> <xsl:variable
>    name="duplicates"
>    select="child::course[count(/descendant::course
> [attribute::code=???]) &gt; 1]"
> />
> 
> The trick is what should replace ???
> 
> Any assistance would be greatly appreciated.  For what's it's 
> worth, I'm using XSLT to generate a linear program that 
> represents the courses our students can take in order to find 
> out what's the  
> smallest number of hours that they'll experience over their 
> program.   
> Sometimes they can choose courses in multiple locations 
> during their program.
> 
> Thanks!
> 
> Jason Foster

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.