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 |
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>
</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>
</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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
"sorted" axis (was: Remove duplicat, Sebastian Rahtz | Thread | Re: "sorted" axis (was: Remove dupl, David Carlisle |
"sorted" axis (was: Remove duplicat, Sebastian Rahtz | Date | Re: "sorted" axis (was: Remove dupl, James Clark |
Month |