Subject: Re: [xsl] Problem in grouping and filering. From: "Jay Bryant" <jay@xxxxxxxxxxxx> Date: Mon, 16 Jan 2006 09:45:49 -0600 |
You have a very common duplicate problem, the solution to which is in the FAQ here: http://www.dpawson.co.uk/xsl/sect2/N2696.html In your case, you need something like this: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" exclude-result-prefixes="fo"> <xsl:output method="xml" indent="yes"/> <xsl:template match="hotels"> <unique-longtext1s> <xsl:for-each select="rate-codes/ref[not(longtext1 = following::longtext1)]"> <xsl:copy-of select="longtext1"/> </xsl:for-each> </unique-longtext1s> </xsl:template> </xsl:stylesheet> Tested with Saxon. Jay Bryant Bryant Communication Services ----- Original Message ----- From: "Bamanie Kumarasena" <bkumarasena@xxxxxxxxxxxxx> To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> Sent: Monday, January 16, 2006 12:43 AM Subject: [xsl] Problem in grouping and filering. > Hi, > > > I am having the following XML ( similar one). I need to filter out the minimum unique 3 rates. But I have no way of keeping a count in XSL > , so I count by the preceding:: node. This counts with the duplicate value. Is there a way to do this ? > > The XML I have : > rates.xml > --------- > <hotels> > <rate-codes> > <rateperday>100</rateperday> > <ref> > <id>3</id> > <longtext1>Daily Leisue Rate</longtext1> > <longtext2></longtext2> > </ref> > </rate-codes> > <rate-codes> > <rateperday>103</rateperday> > <ref> > <id>7</id> > <longtext1>Discounted Leisure Rate</longtext1> > <longtext2></longtext2> > </ref> > </rate-codes> > <rate-codes> > <rateperday>107</rateperday> > <ref> > <id>8</id> > <longtext1>Discounted Leisure Rate</longtext1> > <longtext2></longtext2> > </ref> > </rate-codes> > <rate-codes> > <rateperday>120</rateperday> > <ref> > <id>96</id> > <longtext1>Celebration Package - Lowry Hotel</longtext1> > <longtext2></longtext2> > </ref> > </rate-codes> > ........ > </hotels> > > I need to get all the unique rate details sorted according to rateperday > and filtered the first 3 rates. > > rates.xsl > ----------- > <xsl:template match="hotels"> > > <xsl:variable name = "uniquelist" > select = > "rate-codes[not(ref/longtext1=following::rate-codes/ref/longtext1)]"/> > <xsl:for-each select="$uniquelist"> > <xsl:sort select="rateperday" data-type="number" > order="ascending"/> > <xsl:variable name="count"><xsl:value-of > select="(count(preceding::rate-codes))"/></xsl:variable> > <xsl:if test="$count < 3"> > <xsl:value-of select="."/> > </xsl:if> > </xsl:for-each> > </xsl:template> > > This is the xsl which I have, here I use the count:: preceding , but it > counts the duplicates also. Please send me a quick response as this is > quite urgent. > > > The output I want is > > Daily Leisue Rate > Discounted Leisure Rate > Celebration Package - Lowry Hotel > > But the output I get is: > > Daily Leisue Rate > Discounted Leisure Rate > > > Thanks, > Bamanie. > -- > Bamanie Kumarasena > Software Engineer ( JAVA) > Open World Lanka (Pvt) Ltd, 41 Dutugamunu Street, Pamankada, Dehiwala, > LK > Tel: +94 11 4403904 Ext. 114 > Fax: +94 11 2854815 > http://www.openworld.org/ > > > > > > CONFIDENTIALITY NOTICE The information contained in this message is > confidential, intended only for the use of the individual or the entity > named as recipient. If the reader of this message is not that recipient, > you are notified that any dissemination, distribution or copy of this > message is strictly prohibited. If you have received this message in > error, please immediately notify us by telephone on the number above. > Your co-operation is appreciated.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Problem in grouping and f, Arun Sinha | Thread | Re: [xsl] Problem in grouping and f, Jay Bryant |
Re: [xsl] keeping text together in , G. Ken Holman | Date | [xsl] Accessing a node dynamically , Sumiit Kumar Mukherj |
Month |