Thanks a lot, Geert. Sai. --- On Wed, 6/16/10, Geert Josten <[email protected]> wrote:
From: Geert Josten <[email protected]> Subject: Re: [MarkLogic Dev General] xquery equivalent for perl code To: "General Mark Logic Developer Discussion" <[email protected]> Date: Wednesday, June 16, 2010, 2:38 AM Hi Sai, It has been a while since I worked with Perl, and formatting by my mailclient may have disturbed essential details. If I am right, you are searching for specific string patterns, and want to replace the spaces in matching substrings by underscores. The main problem with you Xquery code is that the replacement argument isn't re-evaluated for each match. It is a fixed string argument, in which only the $ placeholders are replaced by values from each match. So, your local:a function is called only once, and is always returing '$2', making it effectively do nothing at all. So, you will have to take a different approach. You will need something that approaches the xsl:analyze-string kind of functionality. The closest thing in Xquery I know of is the get-matches-and-non-matches function from the xqueryfunction library. More details here: http://www.xqueryfunctions.com/xq/functx_get-matches-and-non-matches.html Hope that helps! Kind regards, Geert > drs. G.P.H. (Geert) Josten Consultant Daidalos BV Hoekeindsehof 1-4 2665 JZ Bleiswijk T +31 (0)10 850 1200 F +31 (0)10 850 1199 mailto:[email protected] http://www.daidalos.nl/ KvK 27164984 De informatie - verzonden in of met dit e-mailbericht - is afkomstig van Daidalos BV en is uitsluitend bestemd voor de geadresseerde. Indien u dit bericht onbedoeld hebt ontvangen, verzoeken wij u het te verwijderen. Aan dit bericht kunnen geen rechten worden ontleend. > From: [email protected] > [mailto:[email protected]] On Behalf Of > sai shanker > Sent: vrijdag 4 juni 2010 15:58 > To: General Mark Logic Developer Discussion > Subject: Re: [MarkLogic Dev General] xquery equivalent for perl code > > Hello All, > To be more specific here is what i am trying to do is - > > declare function local:a($str as xs:string) as xs:string { > fn:replace($str, ' ','_') > }; > > let $str := 'John Doe, ref. nat. dr. med. vet. three ref. nat.' > let $newstr := fn:replace($str,'\s+',' ','i') let $regexp := > "(^| )(dr\.|ref\. nat\.|med. vet. three)( |$)" > return fn:replace($newstr,$regexp,local:a('$2'),'i') > > > i need to pass only the value of $2 wrt to the replace > function (i.e ref. nat. , dr. , med. vet. three , ref. > nat.) to the function which would replace the double space > with a underscore but the literal '$2' gets passed to the > function if i try local:a($2) it complains for a syntax error. > > Is there any possible solution that i can use? > > Thanks and Regards, > Sai. > > > --- On Thu, 6/3/10, sai shanker <[email protected]> wrote: > > > > From: sai shanker <[email protected]> > Subject: [MarkLogic Dev General] xquery equivalent for perl code > To: "General Mark Logic Developer Discussion" > <[email protected]> > Date: Thursday, June 3, 2010, 3:30 PM > > > Hello All, > > I am trying to convert the following perl code into xquery. > but am not getting the expected result. Can you please help me out? > Overview:- I am trying to append an underscore between > multitoken titles. > Perl code:- > > $str='John Smith, ref. nat. dr. med. vet. three ref. nat.'; > print "$str\n"; $str =~ s/\s+/ /g; print "$str\n"; sub a { > my $title = shift; print "title=$title\n"; $title =~ s/ > /_/g; return($title); } $str =~ s/(^| )(dr\.|ref\. > nat\.|med. vet. three)( |$)/$1 . a($2) . $3/eg; $str =~ > s/\s+/ /g; print "$str\n"; > > output --- 'John Smith, ref._nat. dr. med._vet._three ref._nat. > > Thanks and Regards, > Sai. > > > > > > > -----Inline Attachment Follows----- > > > _______________________________________________ > General mailing list > [email protected] > <http://us.mc529.mail.yahoo.com/mc/compose?to=gene...@develope > r.marklogic.com> > http://developer.marklogic.com/mailman/listinfo/general > > > > _______________________________________________ General mailing list [email protected] http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________ General mailing list [email protected] http://developer.marklogic.com/mailman/listinfo/general
