- From: Michael Brundage <xquery@comcast.net>
- Date: Wed, 16 Jul 2003 10:40:31 -0700
- To: "'Jim Whitehead'" <ejw@cse.ucsc.edu>, <ashokma@microsoft.com>, <jim.melton@acm.org>, <Norman.Walsh@Sun.COM>
- Cc: <public-qt-comments@w3.org>
Hi Jim, I believe both of your use cases are already addressed by XQuery 1.0/XPath 2.0: (1) Use a conditional: <xsl:apply-templates select="D:multistatus/D:response"> <xsl:variable name="key" select="D:propstat/D:prop/BIB:pages"/> <xsl:sort select="if(contains($key, '-')) then substring-before($key, '-') else $key" data-type="number"/> </xsl:apply-templates> (2) Here's one way of many ways to do it: define function substring-after-last($str as xs:string?, $sub as xs:string?) as xs:string? { let $last := substring-after($str, $sub) return if ($last) then substring-after-last($last, $sub) else $str } Sincerely, Michael Brundage xquery@comcast.net Writing as Author, "XQuery: The XML Query Language" (Addison-Wesley, to appear 2003) Co-author, "Professional XML Databases" (Wrox Press, 2000) not as Technical Lead Common Query Runtime/XML Query Processing WebData XML Team Microsoft -----Original Message----- From: public-qt-comments-request@w3.org [mailto:public-qt-comments-request@w3.org] On Behalf Of Jim Whitehead Sent: Tuesday, July 15, 2003 5:08 PM To: ashokma@microsoft.com; jim.melton@acm.org; Norman.Walsh@Sun.COM Cc: public-qt-comments@w3.org Subject: Comment on xquery/xpath operators draft Given that you're in last call, I hope these comments aren't too late. I ran into two problems in a recent use of XSLT/XPath 1.0 that do not appear to be well handled by "XQuery 1.0 and XPath 2.0 Functions and Operators", W3C Working Draft 02 May 2003. Problem #1: My application is one that involves handling of bibliographic metadata on academic articles found in the ACM Digital Library. These articles have a page range which may either be a range ("45-203") or a single page ("55"). In my application I wanted to sort the application of templates by the first page number in ascending order (the XML input is the output of a WebDAV PROPFIND method): <xsl:apply-templates select="D:multistatus/D:response"> <xsl:sort select="substring-before(D:propstat/D:prop/BIB:pages, '-')" data-type="number"/> </xsl:apply-templates> This means that I wanted to strip out the numbers up to the dash, if a dash is present, otherwise use all of the numbers present (i.e., from the two previous page ranges, I want "45" and "55"). If I use the substring-before operator (substring-before(., '-') then the first range returns "45" but the single page returns a null string, since there is no dash present. Ideally what I'd like is the absence of the second operator (the dash in my case) cause the entire string to be returned. This operator could be called "substring-before-or-full" or somesuch. It's possible this scenario could be handled by operations on sequences. After reading the specification it wasn't entirely clear. Problem #2: In the same application, I wanted to be able to strip off just the final path segment of an arbitrary length URI. That is, given: http://www.webdav.org/articles/january/webdav.pdf http://ocean.cse.ucsc.edu/repos/articles/january/p3-smith.pdf I'd like to be able to easily strip out "webdav.pdf" and "p3-smith.pdf". Using substring-after doesn't work, since there are an unknown number of "/" characters. ends-with doesn't work either, since I don't know ahead of time what the final path segment will be. What would work is a "substring-after-last(op1, op2)" that returns the substring of op1 after the last op2 in the string. I also ran into lots of problems with date conversions, so I'm really glad to see such a rich set of date operations in the new draft! - Jim Whitehead ejw@cs.ucsc.edu
Received on Wednesday, 16 July 2003 13:47:50 UTC