From wshager at gmail.com Tue Dec 1 05:32:50 2015 From: wshager at gmail.com (W.S. Hager) Date: Tue, 1 Dec 2015 14:32:50 +0100 Subject: [xquery-talk] DOM level 4 Message-ID: Hi, Perhaps this is not the place to discuss this, but I was quite surprised when I stumbled upon the current DOM level 4 spec, which deprecates 4 node types in respect to XML DOM. Are these changes expected to affect XML DOM implementations? Thanks. -- W.S. Hager Lagua Web Solutions http://lagua.nl -------------- next part -------------- An HTML attachment was scrubbed... URL: From mike at saxonica.com Tue Dec 1 07:50:12 2015 From: mike at saxonica.com (Michael Kay) Date: Tue, 1 Dec 2015 15:50:12 +0000 Subject: [xquery-talk] DOM level 4 In-Reply-To: References: Message-ID: > On 1 Dec 2015, at 13:32, W.S. Hager wrote: > > Hi, > > Perhaps this is not the place to discuss this Indeed. I can't see any particular relevance to XQuery. > , but I was quite surprised when I stumbled upon the current DOM level 4 spec, which deprecates 4 node types in respect to XML DOM. > > Are these changes expected to affect XML DOM implementations? > The DOM spec has been hijacked by the HTML crowd, who have no interest in XML at all. It's probably time we deprecated the whole XML DOM, I find it maddening that beginners still use it in preference to far better models like JDOM2 and XOM, simply because the name "DOM" has brand recognition. Michael Kay Saxonica From wshager at gmail.com Tue Dec 1 08:26:02 2015 From: wshager at gmail.com (W.S. Hager) Date: Tue, 1 Dec 2015 17:26:02 +0100 Subject: [xquery-talk] DOM level 4 In-Reply-To: References: Message-ID: Hi Michael, The models you mentioned are both Java APIs, correct? Perhaps a lot more "beginners" use XML DOM instead of better alternatives because those aren't widespread in other languages. HTML DOM, on the other hand, seems to be used mostly in javascript, for obvious reasons. Thanks. 2015-12-01 16:50 GMT+01:00 Michael Kay : > > > On 1 Dec 2015, at 13:32, W.S. Hager wrote: > > > > Hi, > > > > Perhaps this is not the place to discuss this > > Indeed. I can't see any particular relevance to XQuery. > > > > , but I was quite surprised when I stumbled upon the current DOM level 4 > spec, which deprecates 4 node types in respect to XML DOM. > > > > Are these changes expected to affect XML DOM implementations? > > > > The DOM spec has been hijacked by the HTML crowd, who have no interest in > XML at all. > > It's probably time we deprecated the whole XML DOM, I find it maddening > that beginners still use it in preference to far better models like JDOM2 > and XOM, simply because the name "DOM" has brand recognition. > > Michael Kay > Saxonica > > > -- W.S. Hager Lagua Web Solutions http://lagua.nl -------------- next part -------------- An HTML attachment was scrubbed... URL: From christian.gruen at gmail.com Thu Dec 3 03:48:55 2015 From: christian.gruen at gmail.com (=?UTF-8?Q?Christian_Gr=C3=BCn?=) Date: Thu, 3 Dec 2015 12:48:55 +0100 Subject: [xquery-talk] fn:sort: sort for strings in descending order Message-ID: Hi everyone, As you may know, XQuery 3.1 introduces an interesting new fn:sort function, which can be used as alternative for the order by clause in FLWOR expressions [1]. It can e.g. be used to sort numbers in a descending order: sort( 1 to 10, function($k) { -$k } ) I would be interested if anyone has already tried to get the descending order working for strings? sort( ('A', 'AA', 'B'), function($k) { ... } ) I assume that string-to-codepoints could be used, and all Unicode points could then be negated, and additionally longer Unicode sequences would need to be preferred over shorter ones? But maybe there is a more concise solution? Thanks in advance, Christian [1] http://www.w3.org/TR/xpath-functions-31/#func-sort From r.stapper at lijbrandt.nl Thu Dec 3 04:44:33 2015 From: r.stapper at lijbrandt.nl (Rob Stapper) Date: Thu, 3 Dec 2015 13:44:33 +0100 Subject: [xquery-talk] fn:sort: sort for strings in descending order In-Reply-To: References: Message-ID: <000401d12dc8$5c550580$14ff1080$@lijbrandt.nl> Hi Christian, I suppose it can't be this simple: reverse( sort( ('A', 'AA', 'B'))) Rob Stapper -----Oorspronkelijk bericht----- Van: talk-bounces at x-query.com [mailto:talk-bounces at x-query.com] Namens Christian Gr?n Verzonden: donderdag 3 december 2015 12:49 Aan: talk at x-query.com Onderwerp: [xquery-talk] fn:sort: sort for strings in descending order Hi everyone, As you may know, XQuery 3.1 introduces an interesting new fn:sort function, which can be used as alternative for the order by clause in FLWOR expressions [1]. It can e.g. be used to sort numbers in a descending order: sort( 1 to 10, function($k) { -$k } ) I would be interested if anyone has already tried to get the descending order working for strings? sort( ('A', 'AA', 'B'), function($k) { ... } ) I assume that string-to-codepoints could be used, and all Unicode points could then be negated, and additionally longer Unicode sequences would need to be preferred over shorter ones? But maybe there is a more concise solution? Thanks in advance, Christian [1] http://www.w3.org/TR/xpath-functions-31/#func-sort _______________________________________________ talk at x-query.com http://x-query.com/mailman/listinfo/talk --- Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware. http://www.avast.com From mike at saxonica.com Thu Dec 3 05:10:17 2015 From: mike at saxonica.com (Michael Kay) Date: Thu, 3 Dec 2015 13:10:17 +0000 Subject: [xquery-talk] fn:sort: sort for strings in descending order In-Reply-To: <000401d12dc8$5c550580$14ff1080$@lijbrandt.nl> References: <000401d12dc8$5c550580$14ff1080$@lijbrandt.nl> Message-ID: <6B098D3C-2375-4450-A9C9-5577A7C85929@saxonica.com> As Rob points out, the simplest solution for simple cases is to use reverse(). That doesn't work if you want a composite sort key - sort by ascending country then descending city. (Yes, an unconvincing use case, and frankly it's because of the difficulty of finding a convincing use case that we didn't include this capability). If you know that the result of collation-key() will be xs:base64Binary then you can do it, I suspect, by fn:sort($places, function($p) { $p!country, $p!city => collation-key() => bin:not() } ) where bin:not is from http://expath.org/spec/binary#not Michael Kay Saxonica > On 3 Dec 2015, at 12:44, Rob Stapper wrote: > > Hi Christian, > > I suppose it can't be this simple: reverse( sort( ('A', 'AA', 'B'))) > > Rob Stapper > > -----Oorspronkelijk bericht----- > Van: talk-bounces at x-query.com [mailto:talk-bounces at x-query.com] Namens Christian Gr?n > Verzonden: donderdag 3 december 2015 12:49 > Aan: talk at x-query.com > Onderwerp: [xquery-talk] fn:sort: sort for strings in descending order > > Hi everyone, > > As you may know, XQuery 3.1 introduces an interesting new fn:sort function, which can be used as alternative for the order by clause in FLWOR expressions [1]. It can e.g. be used to sort numbers in a descending order: > > sort( > 1 to 10, > function($k) { -$k } > ) > > I would be interested if anyone has already tried to get the descending order working for strings? > > sort( > ('A', 'AA', 'B'), > function($k) { ... } > ) > > I assume that string-to-codepoints could be used, and all Unicode points could then be negated, and additionally longer Unicode sequences would need to be preferred over shorter ones? But maybe there is a more concise solution? > > Thanks in advance, > Christian > > [1] http://www.w3.org/TR/xpath-functions-31/#func-sort > > _______________________________________________ > talk at x-query.com > http://x-query.com/mailman/listinfo/talk > > > --- > Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware. > http://www.avast.com > > > _______________________________________________ > talk at x-query.com > http://x-query.com/mailman/listinfo/talk From mike at saxonica.com Thu Dec 3 06:19:00 2015 From: mike at saxonica.com (Michael Kay) Date: Thu, 3 Dec 2015 14:19:00 +0000 Subject: [xquery-talk] fn:sort: sort for strings in descending order In-Reply-To: <6B098D3C-2375-4450-A9C9-5577A7C85929@saxonica.com> References: <000401d12dc8$5c550580$14ff1080$@lijbrandt.nl> <6B098D3C-2375-4450-A9C9-5577A7C85929@saxonica.com> Message-ID: <917C5CF2-0232-4DCE-9B79-80817653F48B@saxonica.com> > On 3 Dec 2015, at 13:10, Michael Kay wrote: > > As Rob points out, the simplest solution for simple cases is to use reverse(). > > That doesn't work if you want a composite sort key - sort by ascending country then descending city. (Yes, an unconvincing use case, and frankly it's because of the difficulty of finding a convincing use case that we didn't include this capability). > > If you know that the result of collation-key() will be xs:base64Binary then you can do it, I suspect, by > > fn:sort($places, function($p) { $p!country, $p!city => collation-key() => bin:not() } ) > > where bin:not is from http://expath.org/spec/binary#not > Sorry, that's wrong. The empty string sorts first in ascending order, under this function it will still sort first in descending order. Need to do something a bit more subtle. Michael Kay Saxonica From r.stapper at lijbrandt.nl Fri Dec 4 02:07:24 2015 From: r.stapper at lijbrandt.nl (Rob Stapper) Date: Fri, 4 Dec 2015 11:07:24 +0100 Subject: [xquery-talk] fn:sort: sort for strings in descending order In-Reply-To: <917C5CF2-0232-4DCE-9B79-80817653F48B@saxonica.com> References: <000401d12dc8$5c550580$14ff1080$@lijbrandt.nl> <6B098D3C-2375-4450-A9C9-5577A7C85929@saxonica.com> <917C5CF2-0232-4DCE-9B79-80817653F48B@saxonica.com> Message-ID: <000d01d12e7b$9260af40$b7220dc0$@lijbrandt.nl> The difficulty in Christian's case lays in the variable string length. The string length is part of ordering algorithm. For a reverse order one would need to create a string with an inverse string length. I would not know how to create a function nor how to define a collation that does this. I'm not sure if Michael's solution: returning an inverse binary image, how intriguing that one may be, tackles this. (can't check this) So, I would still put my money on the reverse()-method. Rob PS. The composite sort key is another tough cookie to crumble. I feel challenged. -----Oorspronkelijk bericht----- Van: talk-bounces at x-query.com [mailto:talk-bounces at x-query.com] Namens Michael Kay Verzonden: donderdag 3 december 2015 15:19 Aan: Michael Kay CC: talk at x-query.com; Christian Gr?n; Rob Stapper Onderwerp: Re: [xquery-talk] fn:sort: sort for strings in descending order > On 3 Dec 2015, at 13:10, Michael Kay wrote: > > As Rob points out, the simplest solution for simple cases is to use reverse(). > > That doesn't work if you want a composite sort key - sort by ascending country then descending city. (Yes, an unconvincing use case, and frankly it's because of the difficulty of finding a convincing use case that we didn't include this capability). > > If you know that the result of collation-key() will be xs:base64Binary then you can do it, I suspect, by > > fn:sort($places, function($p) { $p!country, $p!city => collation-key() => bin:not() } ) > > where bin:not is from http://expath.org/spec/binary#not > Sorry, that's wrong. The empty string sorts first in ascending order, under this function it will still sort first in descending order. Need to do something a bit more subtle. Michael Kay Saxonica _______________________________________________ talk at x-query.com http://x-query.com/mailman/listinfo/talk --- Dit e-mailbericht is gecontroleerd op virussen met Avast antivirussoftware. http://www.avast.com From mike at saxonica.com Fri Dec 4 02:21:20 2015 From: mike at saxonica.com (Michael Kay) Date: Fri, 4 Dec 2015 10:21:20 +0000 Subject: [xquery-talk] fn:sort: sort for strings in descending order In-Reply-To: <000d01d12e7b$9260af40$b7220dc0$@lijbrandt.nl> References: <000401d12dc8$5c550580$14ff1080$@lijbrandt.nl> <6B098D3C-2375-4450-A9C9-5577A7C85929@saxonica.com> <917C5CF2-0232-4DCE-9B79-80817653F48B@saxonica.com> <000d01d12e7b$9260af40$b7220dc0$@lijbrandt.nl> Message-ID: > > PS. The composite sort key is another tough cookie to crumble. I feel > challenged. > Because fn:sort produces a stable sort, one can always go back to the old punched-card technique of doing multiple sorts, in minor-to-major key order: $places => sort(function($x){$x!city}) => reverse() => sort(function($x){$x!country}) Michael Kay Saxonica From christian.gruen at gmail.com Fri Dec 4 02:52:44 2015 From: christian.gruen at gmail.com (=?UTF-8?Q?Christian_Gr=C3=BCn?=) Date: Fri, 4 Dec 2015 11:52:44 +0100 Subject: [xquery-talk] fn:sort: sort for strings in descending order In-Reply-To: References: <000401d12dc8$5c550580$14ff1080$@lijbrandt.nl> <6B098D3C-2375-4450-A9C9-5577A7C85929@saxonica.com> <917C5CF2-0232-4DCE-9B79-80817653F48B@saxonica.com> <000d01d12e7b$9260af40$b7220dc0$@lijbrandt.nl> Message-ID: Rob, Michael, Thanks for your enlightening answers. The hint to fn:reverse was helpful ? I completely missed it ? and I was not aware of the punched-card technique (I overlooked that sort is stable). One more use I case had in mind were top-k queries: fn:sort(...)[position() = 1 to 5] >From the implementation point of view, such patterns can be sped up with a min heap. I now realize that the heap can simply be replaced with a max heap if an fn:sort call is wrapped by fn:reverse. Christian __________________________________ On Fri, Dec 4, 2015 at 11:21 AM, Michael Kay wrote: >> >> PS. The composite sort key is another tough cookie to crumble. I feel >> challenged. >> > > Because fn:sort produces a stable sort, one can always go back to the old punched-card technique of doing multiple sorts, in minor-to-major key order: > > $places => sort(function($x){$x!city}) => reverse() => sort(function($x){$x!country}) > > Michael Kay > Saxonica