From: Adam R. <ad...@ex...> - 2011-08-25 21:56:41
|
You dont have a trailing and leading space, you just think you do, your encoded string starts and ends with a double-quote i.e. %22, so there are no leading and trailing spaces. On 25 August 2011 23:41, Nate Marks <np...@gm...> wrote: > > I'm using this. a kind of random assortment of spaces and tabs: > > http://localhost:8080/exist/rest/db/orbk-tools/make-id.xql?input=%22%20%20sdfgsfdg%20sfgs%20%20%20%20%20%20%20%20%20ttetrertv%20%20%20%20%20%20%20%22 > ---------- Forwarded message ---------- > From: Adam Retter <ad...@ex...> > Date: Thu, Aug 25, 2011 at 5:00 PM > Subject: Re: [Exist-open] Fwd: xquery remove leading adn trailing whitespace > To: Nate Marks <np...@gm...> > Cc: exi...@li... > > > Whats the string you are using for testing? > > On 25 August 2011 22:58, Nate Marks <np...@gm...> wrote: >> Thanks for the fast response! This -seems- like to should do exactly what >> I >> want, but in the test below it still seems to keep a single space before >> and >> a single space after. Am I nuts?:) >> >> xquery version "1.0"; >> declare namespace exist = "http://exist.sourceforge.net/NS/exist"; >> declare namespace system="http://exist-db.org/xquery/system"; >> declare namespace request="http://exist-db.org/xquery/request"; >> declare option exist:serialize "method=xml media-type=text/xml >> indent=yes"; >> >> let $input := request:get-parameter('input', '') >> let $trimmed := normalize-space($input) >> >> >> >> return >> <results> >> <input>{$input }</input> >> <replace-result>{$trimmed}</replace-result> >> </results> >> >> >> >> ---------- Forwarded message ---------- >> From: Robert Han <rob...@da...> >> Date: Thu, Aug 25, 2011 at 4:44 PM >> Subject: Re: [Exist-open] xquery remove leading adn trailing whitespace >> To: Nate Marks <np...@gm...> >> >> >> Have you tried using normalize-space()? >> >> On Thu, Aug 25, 2011 at 3:40 PM, Nate Marks <np...@gm...> wrote: >>> >>> I've googled a bunch of examples with regular expressions in xquery and >>> can't seem to get any of them to work. ultimately, I'm trying to take a >>> string, get rid of all the leading and trailing whitespace, shrink down >>> all >>> the remaining whitespace to a single space, then replace the spaces with >>> hyphens so I always get a value like: >>> aaa-bbbb-cvccc >>> >>> Any help would be appreciated:) >>> >>> xquery version "1.0"; >>> declare namespace exist = "http://exist.sourceforge.net/NS/exist"; >>> declare namespace system="http://exist-db.org/xquery/system"; >>> declare namespace request="http://exist-db.org/xquery/request"; >>> declare option exist:serialize "method=xml media-type=text/xml >>> indent=yes"; >>> >>> let $input := request:get-parameter('input', '') >>> let $collapsed := xs:token($input) >>> let $trimmed := replace(replace($collapsed,'\s+$',''),'^\s+','') >>> >>> let $twotrimmed := replace(replace($trimmed,'\s+$',''),'^\s+','') >>> let $hyphenated := replace($twotrimmed , ' ', '-') >>> >>> >>> >>> return >>> <results> >>> <input>{$input }</input> >>> <replace-result>{$trimmed}</replace-result> >>> </results> >>> >>> >>> >>> >>> >>> ------------------------------------------------------------------------------ >>> EMC VNX: the world's simplest storage, starting under $10K >>> The only unified storage solution that offers unified management >>> Up to 160% more powerful than alternatives and 25% more efficient. >>> Guaranteed. http://p.sf.net/sfu/emc-vnx-dev2dev >>> _______________________________________________ >>> Exist-open mailing list >>> Exi...@li... >>> https://lists.sourceforge.net/lists/listinfo/exist-open >>> >> >> >> >> -- >> >> _________________________________________________ >> Robert Han >> Dakota Systems, Inc. >> 35 E. Wacker Drive, Suite 1970 >> Chicago, IL 60601 USA >> www.daksys.com >> >> T: 312-263-4400 >> F: 312-263-3400 >> M: 847-609-5845 >> >> >> >> ------------------------------------------------------------------------------ >> EMC VNX: the world's simplest storage, starting under $10K >> The only unified storage solution that offers unified management >> Up to 160% more powerful than alternatives and 25% more efficient. >> Guaranteed. http://p.sf.net/sfu/emc-vnx-dev2dev >> _______________________________________________ >> Exist-open mailing list >> Exi...@li... >> https://lists.sourceforge.net/lists/listinfo/exist-open >> >> > > > > -- > Adam Retter > > eXist Developer > { United Kingdom } > ad...@ex... > irc://irc.freenode.net/existdb > > > ------------------------------------------------------------------------------ > EMC VNX: the world's simplest storage, starting under $10K > The only unified storage solution that offers unified management > Up to 160% more powerful than alternatives and 25% more efficient. > Guaranteed. http://p.sf.net/sfu/emc-vnx-dev2dev > _______________________________________________ > Exist-open mailing list > Exi...@li... > https://lists.sourceforge.net/lists/listinfo/exist-open > > -- Adam Retter eXist Developer { United Kingdom } ad...@ex... irc://irc.freenode.net/existdb |