[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: XSLT 1.0: Problem grouping disparate unordered dat
Hi Ken, Thanks for that. I was able to get it working with my live data on my development system, but unfortunately it seems that the production server has some kind of Xalan misconfiguration which prevents it from resolving the document() reference :-( As the system is going live on Monday, everything else works just fine as it is, and this is for just three lines of information on one page of the 34 sites we're deploying, I don't believe there's any likelihood of getting the configuration issue addressed during crunch time, so I'll have to keep looking for another way. Ah well, it's no fun unless you have one hand tied behind your back ;-) Thanks again, Nick. > At 2006-03-15 18:00 +0000, Nick Fitzsimons wrote: >>Firstly, I'm using XSLT 1.0. > > First in my response is "thank you for supplying test data". > >>The rules for grouping and sorting are fairly simple in the basic case: >> >>Show Gorillas of priority greater than 2, sorted by priority, then by >> date >>descending; >>Show Chimpanzees of priority greater than 2, sorted by priority, then by >>date descending; >>Show Orangutans of priority greater than 2, sorted by priority, then by >>date descending; >>Show Bonobos of priority greater than 2, sorted by priority, then by date >>descending; >>... >>However, I now have the further requirement that I return a single >><section> containing only the first three items (or fewer if less than >>three match the "priority greater than 2" criterion). >>... >>how can I achieve the necessary grouping and sorting? > > I see this only as a sorting issue, since you are returning the > result set in a single section. > >>I'm almost certain some >>straightforward Muenchian grouping will suffice > > If I have understood your requirement, it isn't necessary to use grouping. > > I hope the code below helps. > > . . . . . . . . . . Ken > > T:\ftemp>type nick.xsl > <?xml version="1.0" encoding="ISO-8859-1"?> > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > xmlns:nick="urn:x-nick" > exclude-result-prefixes="nick" > version="1.0"> > > <xsl:output indent="yes"/> > > <nick:type-groupings> > <group type="Gorilla" order="1"/> > <group type="Chimpanzee" order="2"/> > <group type="Orangutan" order="3"/> > <group type="Bonobo" order="4"/> > </nick:type-groupings> > > <xsl:template match="/"> > <xsl:variable name="apes" select="/apes/ape"/> > <section> > <xsl:for-each select="$apes[@priority>2]"> > <xsl:sort select="document('')/*/nick:type-groupings/ > group[@type=current()/@type]/@order" > data-type="number"/> > <xsl:sort select="@priority" order="descending" > data-type="number"/> > <xsl:sort select="substring(@date,7,4)" order="descending"/> > <xsl:sort select="substring(@date,4,2)" order="descending"/> > <xsl:sort select="substring(@date,1,2)" order="descending"/> > <xsl:if test="position()<=3"> > <xsl:element name="{@type}"> > <xsl:copy-of select="@priority | @date"/> > </xsl:element> > </xsl:if> > </xsl:for-each> > </section> > </xsl:template> > > </xsl:stylesheet> > T:\ftemp>type nick1.xml > <apes> > <ape priority="5" date="25-01-2006" type="Chimpanzee" /> > <ape priority="1" date="26-01-2006" type="Gorilla" /> > <ape priority="2" date="29-01-2006" type="Chimpanzee" /> > <ape priority="1" date="22-01-2006" type="Orangutan" /> > <ape priority="3" date="22-01-2006" type="Bonobo" /> > <ape priority="1" date="25-01-2006" type="Bonobo" /> > <ape priority="4" date="24-01-2006" type="Gorilla" /> > <ape priority="5" date="22-01-2006" type="Bonobo" /> > <ape priority="4" date="26-01-2006" type="Chimpanzee" /> > <ape priority="4" date="25-01-2006" type="Gorilla" /> > <ape priority="2" date="25-01-2006" type="Bonobo" /> > <ape priority="3" date="25-01-2006" type="Orangutan" /> > <ape priority="1" date="25-01-2006" type="Bonobo" /> > <ape priority="3" date="27-01-2006" type="Gorilla" /> > <ape priority="1" date="25-01-2006" type="Chimpanzee" /> > <ape priority="1" date="25-01-2006" type="Orangutan" /> > </apes> > > T:\ftemp>xslt nick1.xml nick.xsl con > <?xml version="1.0" encoding="utf-8"?> > <section> > <Gorilla priority="4" date="25-01-2006"/> > <Gorilla priority="4" date="24-01-2006"/> > <Gorilla priority="3" date="27-01-2006"/> > </section> > T:\ftemp>type nick2.xml > <apes> > <ape priority="5" date="25-01-2006" type="Chimpanzee" /> > <ape priority="1" date="26-01-2006" type="Gorilla" /> > <ape priority="2" date="29-01-2006" type="Chimpanzee" /> > <ape priority="1" date="22-01-2006" type="Orangutan" /> > <ape priority="3" date="22-01-2006" type="Bonobo" /> > <ape priority="1" date="25-01-2006" type="Bonobo" /> > <ape priority="5" date="22-01-2006" type="Bonobo" /> > <ape priority="2" date="25-01-2006" type="Bonobo" /> > <ape priority="3" date="25-01-2006" type="Orangutan" /> > <ape priority="1" date="25-01-2006" type="Bonobo" /> > <ape priority="3" date="27-01-2006" type="Gorilla" /> > <ape priority="1" date="25-01-2006" type="Chimpanzee" /> > <ape priority="1" date="25-01-2006" type="Orangutan" /> > </apes> > > T:\ftemp>xslt nick2.xml nick.xsl con > <?xml version="1.0" encoding="utf-8"?> > <section> > <Gorilla priority="3" date="27-01-2006"/> > <Chimpanzee priority="5" date="25-01-2006"/> > <Orangutan priority="3" date="25-01-2006"/> > </section> > T:\ftemp> > > -- > World-wide on-site corporate, govt. & user group XML/XSL training. > 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 (F:-0995) > Male Cancer Awareness Aug'05 http://www.CraneSoftwrights.com/s/bc > Legal business disclaimers: http://www.CraneSoftwrights.com/legal
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|