xquery replace node adds spaces to inline content

Saturday, 5 October 2013 · 7 messages · last reply 7 Oct 2013
FB
France Baril5 Oct 2013 02:44 #
Hi, I'm getting extra spaces after a node replace. Code:
*let **$original* := <div><p>I love flowers (<specify/>).</p>
                          <p>I love flowers: <specify/>.</p></div>

*let* *$specify* := <b><i>red, yellow and white ones</i></b>

*let* *$new* := *copy* *$copy* := *$original*
                    *modify*(*for **$prompt* *in **$copy*//*specify*
                           *return **replace* *node* *$prompt* *with* *
$specify*)
                    *return **$copy*
I would expect $new to give: I love flowers (*red, yellow and white ones*). I love flowers: *red, yellow and white ones*. But I get extra spaces inside the parenthesis of the first sentence and before the period of the second sentence: I love flowers (* red, yellow and white ones** *). I love flowers: *red, yellow and white ones** *. You can try my .xqm on BaseX 7.7 1. Create a DB 'test' with chop white spaces to 'no'. 2. Run access http://*localhost:8984*/test-extra-spaces/test-1 from your browser. 3. Look at the .xml in the test DB. It has extra carriage return. It looks like the query assumed that <i> was a block and it felt compelled to add a carriage return and indent.
-- France Baril Architecte documentaire / Documentation architect france.baril at architextus.com (514) 572-0341
CG
Christian Grün6 Oct 2013 01:09 #
Hi France, you should get the desired result by adding the following line to the beginning of your query:
  declare option output:indent 'no';
Hope this helps, Christian PS: I’ll try my best to answer your pending mail tomorrow. ___________________________ 2013/10/5 France Baril <france.baril at architextus.com>:
Quoted text · France Baril · 54 lines
> Hi, > > I'm getting extra spaces after a node replace. > > Code: > > let $original := <div><p>I love flowers (<specify/>).</p> > <p>I love flowers: <specify/>.</p></div> > > let $specify := <b><i>red, yellow and white ones</i></b> > > let $new := copy $copy := $original > modify(for $prompt in $copy//specify > return replace node $prompt with $specify) > return $copy > > > I would expect $new to give: > > I love flowers (red, yellow and white ones). > > I love flowers: red, yellow and white ones. > > > But I get extra spaces inside the parenthesis of the first sentence and > before the period of the second sentence: > > I love flowers ( red, yellow and white ones ). > > I love flowers: red, yellow and white ones . > > > You can try my .xqm on BaseX 7.7 > > 1. Create a DB 'test' with chop white spaces to 'no'. > 2. Run access http://localhost:8984/test-extra-spaces/test-1 from your > browser. > 3. Look at the .xml in the test DB. It has extra carriage return. It looks > like the query assumed that <i> was a block and it felt compelled to add a > carriage return and indent. > > > > -- > France Baril > Architecte documentaire / Documentation architect > france.baril at architextus.com > (514) 572-0341 > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >
CG
Christian Grünin reply to France Baril, 7 Oct 2013, 16:367 Oct 2013 14:39 #
Quoted text · France Baril · 2 lines
> I tried that, I figured it was not supported: > [XQST0108] No output declarations allowed in library modules.
True, this is a restriction of the XQuery 3.0 specification. However, output declarations are allowed in main modules, and since 7.7, you can specify your RESTXQ functions both in library and main modules [1]. Hope this helps, Christian [1] http://docs.basex.org/wiki/RESTXQ
CG
Christian Grün7 Oct 2013 16:08 #
Hi France, one more solution to your indentation issue: if you add an xml:space attribute to the root node of your updated element, no extra indentations wil be added to your output:
let $original := <div xml:space="preserve">...
And now I’ll finally have a look at your frequently cited mail, Christian ___________________________ 2013/10/7 Christian Grün <christian.gruen at gmail.com>:
Quoted text · Christian Grün · 12 lines
>> I tried that, I figured it was not supported: >> [XQST0108] No output declarations allowed in library modules. > > True, this is a restriction of the XQuery 3.0 specification. However, > output declarations are allowed in main modules, and since 7.7, you > can specify your RESTXQ functions both in library and main modules > [1]. > > Hope this helps, > Christian > > [1] http://docs.basex.org/wiki/RESTXQ
CG
Christian Grünin reply to France Baril, 7 Oct 2013, 18:097 Oct 2013 16:19 #
Quoted text · France Baril · 2 lines
> Or should I convert all modules with functions that are not using rest path > to main modules so I can declare the output option?
Well, similar to that (I hope I got you right)... You can convert all of your modules, which include RESTXQ annotations, to main modules. A main module needs to end with a valid XQuery expression, which can e.g. be an empty sequence (). It’s true that main modules can’t be imported from other modules. In our own projects, RESTXQ modules basically serve as entry points, and most of the application logic is stored in other modules (which we store in the repository).
FB
France Barilin reply to Christian Grün, 6 Oct 2013, 01:097 Oct 2013 16:36 #
I tried that, I figured it was not supported: [XQST0108] No output declarations allowed in library modules. I get the error even when declaring the namespace: *declare namespace **output* = " http://www.w3.org/2010/xslt-xquery-serialization"; After multiple tries, I was able to get it with this: *declare* %rest:path("/test-extra-spaces/test-1") %rest:GET %output:method('html') %output:html-version('5.0') %output:indent('no')... However, I'd still like to know what I am missing when I get the first error because a lot of update functions don't have a rest path. So the *declare option output:indent 'no'; *would be quite useful. Big thanks! On Sat, Oct 5, 2013 at 7:09 PM, Christian Grün <christian.gruen at gmail.com>wrote:
Quoted text · Christian Grün · 71 lines
> Hi France, > > you should get the desired result by adding the following line to the > beginning of your query: > > declare option output:indent 'no'; > > Hope this helps, > Christian > > PS: I’ll try my best to answer your pending mail tomorrow. > ___________________________ > > 2013/10/5 France Baril <france.baril at architextus.com>: > > Hi, > > > > I'm getting extra spaces after a node replace. > > > > Code: > > > > let $original := <div><p>I love flowers (<specify/>).</p> > > <p>I love flowers: <specify/>.</p></div> > > > > let $specify := <b><i>red, yellow and white ones</i></b> > > > > let $new := copy $copy := $original > > modify(for $prompt in $copy//specify > > return replace node $prompt with $specify) > > return $copy > > > > > > I would expect $new to give: > > > > I love flowers (red, yellow and white ones). > > > > I love flowers: red, yellow and white ones. > > > > > > But I get extra spaces inside the parenthesis of the first sentence and > > before the period of the second sentence: > > > > I love flowers ( red, yellow and white ones ). > > > > I love flowers: red, yellow and white ones . > > > > > > You can try my .xqm on BaseX 7.7 > > > > 1. Create a DB 'test' with chop white spaces to 'no'. > > 2. Run access http://localhost:8984/test-extra-spaces/test-1 from your > > browser. > > 3. Look at the .xml in the test DB. It has extra carriage return. It > looks > > like the query assumed that <i> was a block and it felt compelled to add > a > > carriage return and indent. > > > > > > > > -- > > France Baril > > Architecte documentaire / Documentation architect > > france.baril at architextus.com > > (514) 572-0341 > > > > _______________________________________________ > > BaseX-Talk mailing list > > BaseX-Talk at mailman.uni-konstanz.de > > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk > > >
-- France Baril Architecte documentaire / Documentation architect france.baril at architextus.com (514) 572-0341
FB
France Barilin reply to Christian Grün, 7 Oct 2013, 14:397 Oct 2013 18:09 #
*I'm not sure that I get what we are trying to achieve with main modules here:* - Should I create a main module in which I import all library modules so they inherit the output option? - Or should I convert all modules with functions that are not using rest path to main modules so I can declare the output option? - What are other consequences of using main modules? How will I import a main module to make its functions available to other modules? *My scheme is:* User comes in with one of: - http://host:port/menu?id=x in menu.xqm - http://host:port/topic?id=y in topic.xqm Both menu.xqm and topic.xqm import a module with common functions (contentrefs.xqm) that resolve content references, for example: contentref:fill-with-product-name(content as node(), product as xs:string) contentref:fill-with-product-name is the one that makes the node replacement (similar to the flower example). *My 'scheme'-related question is:* Should contentrefs.xqm really be converted to a main module?

⚡Generated with XQuery