xsl-list
[Top] [All Lists]

Re: [xsl] Sorting by child element count

2010-12-29 09:40:01
The sort criteria can be any calculation, it does not have to be performed on data found in the instance, therefore the criteria is simply expressed as:

  <xsl:apply-templates select="Item">
    <xsl:sort select="count(Data)" data-type="number"/>
  </xsl:apply-templates>

I hope this helps.

. . . . . . . . . . Ken

At 2010-12-29 07:21 -0800, Mark wrote:
Happy new year! Thanks for all the help this list has given me over the past two years. My question:

I have an XML document that looks like the listing below. I want to sort the <List> by <Item> so that all the <Items> with one <Data> element are followed by all the <Items> with two <Data> elements, and so on, until the last <Items> in the output list have the most <Data> elements. The <Data> elements have to remain inside their original parent <Item>.

No clue how to begin. Can you point me in the right direction?

Thanks,
Mark

<List>
   <Item>
       <Data>...</Data>
... <!?possibly 1 to 10 or so <Data> elements in each parent <Item> element.
       <Data>...</Data>
   </Item>
    ... <!?400 <Item> elements in the <List> ­>
</List>


--
Contact us for world-wide XML consulting & instructor-led training
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
G. Ken Holman                 mailto:gkholman(_at_)CraneSoftwrights(_dot_)com
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--