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

Re: Sorting things on two levels

Subject: Re: Sorting things on two levels
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 14 Apr 2015 16:38:34 -0000
Re:  Sorting things on two levels
Michele R Combs mrrothen@xxxxxxx wrote:

Looks like grouping and sorting to me. Do you use XSLT 1.0 or 2.0?


I'll be running the transform using the latest version of Oxygen, so it looks like either would be fine. From the Oxygen Help file:

With XSLT 2.0 here is an approach:


<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs">


<xsl:output method="html" indent="yes"/>

<xsl:template match="root">
<ul>
<xsl:for-each-group select="indexterm" group-by="primary">
<xsl:sort select="current-grouping-key()"/>
<li>
<xsl:value-of select="current-grouping-key(), if (not(current-group()/secondary)) then current-group()/@id else ()" separator=", "/>
<xsl:if test="current-group()/secondary">
<ul>
<xsl:for-each-group select="current-group()" group-by="secondary">
<xsl:sort select="current-grouping-key()"/>
<li>
<xsl:value-of select="current-grouping-key(), current-group()/@id" separator=", "/>
</li>
</xsl:for-each-group>
</ul>
</xsl:if>
</li>
</xsl:for-each-group>
</ul>
</xsl:template>


</xsl:stylesheet>

Outputs

<ul>
   <li>aardvarks, {ID}</li>
   <li>bears
      <ul>
         <li>breeding, {ID}</li>
         <li>feeding, {ID}</li>
         <li>hunting, {ID}, {ID}</li>
      </ul>
   </li>
</ul>

for your sample data.

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.