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

Re: basename string sort and group

Subject: Re: basename string sort and group
From: davep <davep@xxxxxxxxxxxxx>
Date: Sat, 03 Sep 2011 13:51:56 +0100
Re:  basename string sort and group
On 09/03/2011 01:10 PM, Martin Honnen wrote:
davep wrote:
Given input such as
<fonts>
<entry
href="/apps/jdk/lib/fonts/LucidaTypewriterRegular.ttf">Lucida</entry>
<entry href="/apps/jdk/lib/fonts/LucidaTypewriterBold.ttf">Lucida</entry>
<entry
href="/apps/jdk/lib/oblique-fonts/LucidaSansDemiOblique.ttf">Lucida</entry>


</fonts>

I want to sort and group by directory, for an output such as

<fonts>
<dir href="/apps/jdk/lib/fonts">
<entry href="LucidaTypewriterRegular.ttf">Lucida</entry>
<entry href="LucidaTypewriterBold.ttf">Lucida</entry>
</dir>
<dir href="/apps/jdk/lib/oblique-fonts">
<entry href="LucidaSansDemiOblique.ttf">Lucida</entry>
</dir>

etc.

I.e. Isolate the directories, then group all entries within that directory.


<xsl:template match="fonts">
<xsl:copy>
<xsl:for-each-group select="entry"
group-by="string-join(tokenize(@href, '/')[position() lt last()], '/')>
<dir href="{current-grouping-key()}">
<xsl:apply-templates select="current-group()"/>
</dir>
</xsl:for-each-group>
</xsl:copy>
</xsl:template


<xsl:template match="entry">
<entry href="{tokenize(@href, '/')[last()]}">
<xsl:value-of select="."/>
</entry>
</xsl:template>

Untested.



Thanks Martin. Appreciated.




regards


--
Dave Pawson
XSLT XSL-FO FAQ.
http://www.dpawson.co.uk

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.