[XQZone General] XQuery "grepping" idiom
McBeath, Darin W. (ELS)
D.McBeath at elsevier.com
Fri Oct 8 05:23:38 PDT 2004
Hi David.
Here is one possibility that you might try.
If the birthdays structure is stored as an XML document inside of CIS, you
could potentially use the xdmp:estimate function to boost performance ...
but, you could not use an attribute (date) since you will get an
'xdmp:unsearchable' error.
So, if your XML was stored in CIS and it looked something like the
following:
<birthdays>
<born-date>1967-05-11</born-date>
<born-date>1959-03-01</born-date>...
</birthdays>
xdmp:estimate(cts:search(//born-date, cts:word-query("1967"))) would return
a non-zero value if 1967 occurred somewhere in one of the born-date fields.
I'm assuming that '-' was a word delimeter when the content was loaded.
Hope this is helpful.
Darin.
-----Original Message-----
From: general-bounces at xqzone.marklogic.com
To: General XQZone Discussion
Sent: 10/7/2004 10:59 PM
Subject: [XQZone General] XQuery "grepping" idiom
Given the following XQuery search need, I'd like feedback on whether my
solution is optimal.
Assume an XML data structure like so:
define variable $bdays {
<birthdays>
<born date="1967-05-11"/>
<born date="1959-03-01"/> ...
</birthdays>
}
Let's say @date is typed as xs:string. I want to determine whether a
particular year is contained in the birthday data. I can't test for
$year = $bdays/born/@date
because $year must match the entire @date string. Unfortunately I
can't do
$year = substring-before($bdays/born/@date, '-')
because the first argument to substring-before() is not a string value.
So is the following the most elegant way to do the test?
$year = ( for $string in $bdays/born/@date
return substring-before($string, '-'))
Because the right side evaluates to the sequence ('1967', '1959') the
expression will be true when $year = one of those values.
Is there a more compact XQuery function to use here?
--
David Sewell, Editorial and Technical Manager
Electronic Imprint, The University of Virginia Press
PO Box 400318, Charlottesville, VA 22904-4318 USA
Courier: 310 Old Ivy Way, Suite 302, Charlottesville VA 22903
Email: dsewell at virginia.edu Tel: +1 434 924 9973
Web: http://www.ei.virginia.edu/
_______________________________________________
General mailing list
General at xqzone.marklogic.com
http://xqzone.com/mailman/listinfo/general
More information about the General
mailing list