|
[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message] RE using a variable within a regexp patternHans-Juergen Rennau hrennau at yahoo.deThu Oct 1 22:13:38 PDT 2009
Hi Manual,
if I understand you correctly, you wonder how you can compose a match pattern from variable and fixed parts, e.g. framing a variable term by an initial ^ and a trailing $, right?
The solution is simple: use an _expression_ whose string value is the desired sequence of characters. Often this will be achieved using the concat function, whose arguments in turn may be literals, variable references, function calls, path expressions.... Examples:
matches(., concat('^', $q, '$'))
matches(., concat($prefix, $q, $postfix))
matches(., concat('^', 'ID', position()))
matches(., concat('^', $n/@criterion, '.*s'))
So the task becomes very simple if you remember that the way an expression is resolved to a value is independent on the context where the value is used. Therefore, you need not any special knowledge about the matches function - all you need is the general understanding how to build an expression that resolves to the intended string.
With kind regards,
Hans-Juergen
------------------------------
Message: 4
Date: Thu, 1 Oct 2009 20:53:29 +0200
From: Manuel Souto Pico <http://x-query.com/mailman/listinfo/talk>
Subject: using a variable within a regexp pattern in
XQuery
To: http://x-query.com/mailman/listinfo/talk
Message-ID:
<http://x-query.com/mailman/listinfo/talk>
Content-Type: text/plain; charset="iso-8859-1"
Hi,
I'm a bit stuck trying to run a regexp pattern in a XQuery search file.
(1) where $record/langSet[@xml:lang="en"]/tig/term[matches(., $q)]
works
(2) where $record/langSet[@xml:lang="en"]/tig/term[matches(.,
"$q")] doesn't work
(3) where $record/langSet[@xml:lang="en"]/tig/term[matches(.,
"^$q.*$")] doesn't work
(4) where $record/langSet[@xml:lang="en"]/tig/term[matches(.,
"^bu.+$")] works!
Any ideas about how I can get to use regular expressions in this query?
(4) retrieves 'bufer', 'bug' and 'bus'. If $q is 'bu', (1) retrieves as well
'attri*bu*te', 'contrast *bu*tton', etc.
Thanks a lot!
Cheers, Manuel
|
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
|






