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

Re: "sorted" axis (was: Remove duplicates from a node-set ac

Subject: Re: "sorted" axis (was: Remove duplicates from a node-set according to content)
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Wed, 28 Jul 1999 11:00:13 -0400
francis d arcy godolphin osborne
At 99/07/28 14:46 +0000, Sebastian Rahtz wrote:
>My issue is the
>processing of a sorted list, and extracting just the different
>values. My data looks something like this:
...
>that is to say, a set of <stone>s containing several <person>s who
>have a <died> date. What I want to end up with is
>
> 1959
>   Another, Francis
> 1964
>   Godolphin, Francis
>   TheLast, Francis
...
>Can anyone suggest good ways of solving the problem using what we
>have now?  For those who are interested, David Carlisle _did_ find a nice
>solution for me (data:
>http://users.ox.ac.uk/~rahtz/xslcourse/data.xml, 
>solution: http://users.ox.ac.uk/~rahtz/xslcourse/ex23.xsl) but it has
>to use a little brute force and as a result is a trifle slow (it takes 
>35 minutes to process a 2.5Mbyte input file --- I have only tried it
>with XT, as it is written using July XSL syntax)

I don't think there is another approach with the given WD.

After writing the script below, I now see it is based on the identical
principles that David used, so it will probably also be just as slow.

............. Ken



T:\FTEMP>type test.xml
<?xml version="1.0"?>
<cemetery>
<person><name><fnm>Francis d'Arcy
   Godolphin</fnm><snm>Osborne</snm></name><died><date><day>20</day><mon>
   3</mon><yr>1964</yr></date></died></person>
<person><name><fnm>Francis d'Arcy
   Another</fnm><snm>Osborne</snm></name><died><date><day>20</day><mon>
   3</mon><yr>1959</yr></date></died></person>
<person><name><fnm>Francis d'Arcy
   TheLast</fnm><snm>Osborne</snm></name><died><date><day>20</day><mon>
   3</mon><yr>1964</yr></date></died></person>
</cemetery>
T:\FTEMP>type test.xsl
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0">

<xsl:template match="/">                              <!--root rule-->
  <xsl:for-each select="//person">           <!--process all people-->
    <xsl:sort select="died/date/yr"/>
    <xsl:variable name="year" select="died/date/yr"/>
                         <!--process only one entry per sorted year-->
    <xsl:if test="not(preceding-sibling::person[died/date/yr=$year])">
      <xsl:value-of select="$year"/>
      <xsl:text>&#xa;</xsl:text>
                          <!--reselect only those in the given year-->
      <xsl:for-each select="//person[died/date/yr=$year]">
        <xsl:sort select="name/snm"/>
        <xsl:sort select="name/fnm"/>
        <xsl:value-of select="name/fnm"/><xsl:text>&#xa;</xsl:text>
      </xsl:for-each>
    </xsl:if>
  </xsl:for-each>
</xsl:template>

</xsl:stylesheet>

T:\FTEMP>call xsl test.xml test.xsl test.txt
T:\FTEMP>type test.txt
1959
Francis d'Arcy
   Another
1964
Francis d'Arcy
   Godolphin
Francis d'Arcy
   TheLast

T:\FTEMP>


--
G. Ken Holman                    mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.             http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0   +1(613)489-0999   (Fax:-0995)
Website:  XSL/XML/DSSSL/SGML services, training, libraries, products.
Publications:   Introduction to XSLT (3rd Edition) ISBN 1-894049-00-4
Next instructor-led training:   MS'99 1999-08-16  MT'99 1999-12-05/06


 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.