Re: [basex-talk] XQuery Update delete attributes

2020-09-27 Thread Martin Honnen






Question to Christian: why does

  . update delete node descendant-or-self::*/@class

work for me but

/ update delete node descendant-or-self::*/@class

gives an error unexpect end of query.



OK, / update is ambigious, it has to be


(/) update delete node //@class

to make sure the update is not seen as a child node selection of update
elements to the root node /.





Re: [basex-talk] XQuery Update delete attributes

2020-09-27 Thread Martin Honnen



On 27.09.2020 14:48, Günter Dunz-Wolff wrote:

Hi all,
can’t figure it out. Is there any way in XQuery Update, to delete a specific 
attribute from any node?



Doesn't

  delete node //@foo

delete all "foo" attributes?

Or

. update delete node descendant-or-self::*/@foo

?


Question to Christian: why does

  . update delete node descendant-or-self::*/@class

work for me but

/ update delete node descendant-or-self::*/@class

gives an error unexpect end of query.



Re: [basex-talk] Accessing Flexmark (Java) from Query

2020-09-20 Thread Martin Honnen



On 20.09.2020 01:41, Andreas Mixich wrote:

Am 19.09.2020 um 23:30 schrieb Martin Honnen:

import com.vladsch.flexmark.parser.Parser.Builder;

with

   $builder => Parser.Builder:build()

Hello Martin,

thanks for taking the time!

I am not quite sure I understand. Do you want me to:

   import module namespace Parser.Builder =
"java:com.vladsch.flexmark.parser.Parser.Builder";



I am not sure I have completely understood the reflection and namespace
conventions but after some reading and testing it seems the inner class
Builder should be accessible by


declare namespace Builder =
'java:com.vladsch.flexmark.parser.Parser$Builder';


and then

$builder => Builder:build()


should work for the variable

let $builder := Parser:builder($mds)

you have, you should be able to chain

MutableDataSet:new() => Parser:builder() => Builder:build()



Re: [basex-talk] Accessing Flexmark (Java) from Query

2020-09-19 Thread Martin Honnen

On 19.09.2020 22:54, Andreas Mixich wrote:

Hi,

how can I translate this Java[1] to XQuery according to [2]?

   package com.vladsch.flexmark.samples;

   import com.vladsch.flexmark.util.ast.Node;
   import com.vladsch.flexmark.html.HtmlRenderer;
   import com.vladsch.flexmark.parser.Parser;
   import com.vladsch.flexmark.util.data.MutableDataSet;

   public class BasicSample {
   public static void main(String[] args) {
   MutableDataSet options = new MutableDataSet();

   // uncomment to set optional extensions
   //options.set(Parser.EXTENSIONS,
Arrays.asList(TablesExtension.create(), StrikethroughExtension.create()));

   // uncomment to convert soft-breaks to hard breaks
   //options.set(HtmlRenderer.SOFT_BREAK, "\n");

   Parser parser = Parser.builder(options).build();
   HtmlRenderer renderer = HtmlRenderer.builder(options).build();

   // You can re-use parser and renderer instances
   Node document = parser.parse("This is *Sparta*");
   String html = renderer.render(document);  // "This is
Sparta\n"
   System.out.println(html);
   }
   }

I only get so far as to:

   declare namespace Node = "com.vladsch.flexmark.util.ast.Node";
   declare namespace HtmlRenderer =" com.vladsch.flexmark.html.HtmlRenderer";
   declare namespace Parser = "com.vladsch.flexmark.parser.Parser";
   declare namespace MutableDataSet =
"com.vladsch.flexmark.util.data.MutableDataSet";

   declare option db:checkstrings 'false';

   let $mds := MutableDataSet:new()
   let $builder := Parser:builder($mds)
   return $builder

which results in

   DataSet{dataSet={}}

I found no documentation, on how to translate something as

   Parser.builder(options).build()

to XQuery. How do I express the method

   build()

of the instance

   Parser.builder(options)

I just created?




Does

import com.vladsch.flexmark.parser.Parser.Builder;

with

  $builder => Parser.Builder:build()

work?



Re: [basex-talk] Best way to re-create existing root element with all attributes

2020-09-13 Thread Martin Honnen

On 13.09.2020 21:46, Yitzhak Khabinsky wrote:

Hello,

This is input XML:


Peter
Director

John
Animator

James
Assistant




Desired output XML:


Peter
Director


Overall, it is a so called ‘modified identity transformation’ in XSLT
parlance.

Output XML shall be the same, except the child  element and
its children.

**

Question:

*What is the best way to re-create existing root element with all its
attributes?*

My implementation:

xquery version "3.1";

declare context item := document {



     Peter

     Director

     

     John

     Animator

     

     James

     Assistant

     

     



};

(: working version :)

element {fn:node-name(/*)}

{

let $y :=  ./*/@*

return $y,    (: copy all attributes :)

for $x in ./*/(* except employee)

return $x

}

(: NOT working version, trying to make it more concise :)



I would write

  /*/element { node-name() } { @*, * except employee }





Re: [basex-talk] Yaml serialization

2020-08-12 Thread Martin Honnen

Am 12.08.2020 um 12:38 schrieb Christian Grün:


YAML serialization would be a nice feature indeed.

Are you aware of existing (ideally bidirectional) mappings that would be
appropriate for general use?


At XML Prague, Norm did a demo of casting YAML to JSON as described in
https://so.nwalsh.com/2020/02/15/xproc-30, he said there he has that
built in into his (some day) upcoming XProc 3 processor. I am not sure
the other direction is supported as well and while there is some
repository containing "Calabash 2" doing some cast
https://github.com/ndw/xmlcalabash2/blob/84b06fbd8331797d1b91f96646d4e55dd9ab26a9/src/main/scala/com/xmlcalabash/steps/CastContentType.scala#L287
I have no idea it reflects the approach used in the demo or whether it
makes sense for any general YAML to JSON mapping.



Re: [basex-talk] Inserting a two double quoted attribute

2020-07-27 Thread Martin Honnen

Am 27.07.2020 um 12:01 schrieb Ramzi Hammouda:

Hello BaseX team,

I need to insert a node that has an attribute with two double quotes.

An example:

let $message:='3.00'


With XML markup, to have an attribute value delimited by double quotes
but to also use double quotes inside the attribute value, you need to
use an entity reference or character reference in the attribute value
  3.00
to escape the double quote(s).



return insert nodes fn:parse-xml-fragment($message)

as last into doc('testingdb/testing.xml')

The GBP attribute is with two “ so it gives the error:

SAX: file://C:/Program$20Files(86)/BaseX/(Line1)
: whitespace expected,
attribute name found.

How can I solve the issue?


P/Respectons ensemble l'environnement. N'imprimez ce message que si
nécessaire. //Let's respect the environment together. Only print this
message if necessary./




Re: [basex-talk] Joining large files

2020-07-11 Thread Martin Honnen

On 11.07.2020 14:41, Giuseppe G. A. Celano wrote:


I am trying to perform a join operation between two large XML files
(~490 MB and ~40 MB), which are the result of the automatic conversion
of old sql dumps into XML files. I created two databases for the files.
The query I wrote to join them is correct because it works when I limit
the join to just a few items, but it never ends if I apply it to all items:

here is the xquery:
https://git.informatik.uni-leipzig.de/celano/perseus_morpheus/-/blob/master/join_files.xq
here is the first file:




Saxon EE seems to be capable of handling it (loading the files with the
doc function of course instead of from a db), although needing more than
2GB of memory.

Not sure where BaseX struggles, I am sure someone of the BaseX team can
tell you soon.

Saxon HE also struggles so it must be some of the advanced join
optimizations in EE that allow it to run that query in a reasonable time.


Re: [basex-talk] Joining large files

2020-07-11 Thread Martin Honnen

Am 11.07.2020 um 14:41 schrieb Giuseppe G. A. Celano:


I am trying to perform a join operation between two large XML files
(~490 MB and ~40 MB), which are the result of the automatic conversion
of old sql dumps into XML files. I created two databases for the files.
The query I wrote to join them is correct because it works when I limit
the join to just a few items, but it never ends if I apply it to all items:

here is the xquery:
https://git.informatik.uni-leipzig.de/celano/perseus_morpheus/-/blob/master/join_files.xq


Isn't the
   where $nn
kind of meaningless? I don't think you can have an empty sequence $nn,
as you don't use `allowing empty` when you bind that variable in the
nested `for`.

No idea of course whether that changes the problem you encounter.





Re: [basex-talk] How to serialize HTML as text

2020-06-27 Thread Martin Honnen

Am 27.06.2020 um 18:32 schrieb Emmanuel Chateau:


I need to output a JSON object with HTML content without a parent element. 
Weird idea I grant you, but required by the people I work with.

Working from a map, in the map value, the content should not appear in a parent 
element. Instead of :

```
map {
 ‘key' : ‘value’,
 ‘content’ : this is some content etc
}
```

I would like to output something like

```
map {
 ‘key' : ‘value’,
 ‘content’ : 'this is some content etc'
}
```

Is there a way to output some HTML content without the parent element in XQuery 
?



Assuming you have the span element node, simply call the serialize
function on its child nodes e.g.

serialize(this is some content etc/node(), map {
'method' : 'html'})




Re: [basex-talk] sum() is returning inaccurate sums

2020-06-17 Thread Martin Honnen

Am 17.06.2020 um 10:50 schrieb Martin Honnen:


Whether you do that with a long `for .. return` or simply with
   //gross/xs:decimal(.)
or
   //gross!xs:decimal(.)
is up to you.

Schema-aware XQuery could also help of the `gross` elements were
declared as `xs:decimal`, but I don't think XQuery supports schema-aware
XQuery.


That last sentence was supposed to say:


Schema-aware XQuery could also help if the `gross` elements were
declared as `xs:decimal`, but I don't think BaseX supports schema-aware
XQuery.


Re: [basex-talk] sum() is returning inaccurate sums

2020-06-17 Thread Martin Honnen

Am 17.06.2020 um 10:37 schrieb Jay Straw:

Hi all,

I'm building a budgeting system for home use, using XSLTForms and --
ready for it? -- BaseX!

sum() has been behaving weird. I'm adding USD, which means only 2
decimals of precision. But depending on the combination of elements I
add, I'll get a long double that's inaccurate. Sometimes it returns what
I expect, sometimes it doesn't, but either case is repeatable.

Take these 3 receipts:

1 --

   
     2020-06-08
     
       Frigid North
       
     
     Jay
     Debit
     shop-general
     6.50
     0.00
     6.50
   
   
     Start Capacitor (for old rockwell saw/jointer motor)
     6.50
     1
     6.50
     shop-general
   


2 --

   
     2020-06-09
     
       Home Depot
       Tudor
     
     Jay
     Cash
     jay-misc
     9.87
     0
     9.87
   
   
     Stainless Protractor
     9.87
     1
     9.87
     jay-misc
   


3 --

   
     2018-09-16
     
       Title Wave
       Midtown
     
     Franny
     Debit
     books
     20.85
     
     20.85
   
   
     Music of the Spheres
     books
     6.95
     1
     6.95
   
   
     Magic Mirror of M. C. Escher
     8.95
     1
     8.95
     books
   
   
     Daumier 120 Great Lithographs
     4.95
     1
     4.95
     books
   


When I sum the  elements:
sum 1 & 2 = 16.367
sum 1 & 3 = 27.35
sum 2 & 3 = 30.72

What makes certain combinations return such crazy numbers?

I did find one other thread in the mailing list about this, it got an
answer but didn't really explain much. I have a schema for prices in the
XForm, should I be loading that somehow? The only workaround I have now
is like, "let $grosses:= for $gross in $receipts//gross return
xs:decimal($gross)" but I'm hoping there's a more straightforward way.

Not sure if this is implementation specific or if it's not defined or
what. If I should ask elsewhere, please let me know :-)


The "default" xs:double data type used in XPath and XQuery is known to
have such inaccuracies so (try the same sum in JavaScript and you should
see similar results), yes, you need to use `xs:decimal` explicitly to
avoid such problems.

Whether you do that with a long `for .. return` or simply with
  //gross/xs:decimal(.)
or
  //gross!xs:decimal(.)
is up to you.

Schema-aware XQuery could also help of the `gross` elements were
declared as `xs:decimal`, but I don't think XQuery supports schema-aware
XQuery.





Re: [basex-talk] Serializing with xml-stylesheet prolog

2020-06-07 Thread Martin Honnen

Am 07.06.2020 um 10:25 schrieb Jay Straw:


I need to run a client-side stylesheet (XSLTForms, I tried it server
side, didn't work), but getting my assembled XHTML document to output
with  has been hard. After searching
https://docs.basex.org/wiki/Serialization,
http://www.w3.org/TR/xslt-xquery-serialization-31/#serparams-in-xdm-instance,
searching this list, lots of googling with prolog/declaration/other
words, I came up empty. So I tried other things.

But those other things worked poorly, and when things did come out in
the right order, with the right namespaces etc, the single page app that
worked as a standalone document, doesn't work. If I copy and paste raw
output from basex that my browser receives, put it in a new file in the
same directory, and open that in my browser it works fine. So there's
gotta be some issue with my workaround.

So I'm hoping you can tell me what I've missed in my searches, so that I
don't need a workaround :-)


Basically that is not part of the prolog, rather it is a processing
instruction https://www.w3.org/TR/xquery-31/#id-computed-pis before the
root element so you need e.g.

document {
processing-instruction xml-stylesheet { 'type="text/xsl"
href="sheet.xsl"' },
http://www.w3.org/1999/xhtml;>
...

}





Re: [basex-talk] Runtime load of a module?

2020-05-17 Thread Martin Honnen

Am 17.05.2020 um 16:46 schrieb Buddy Kresge:

We have a situation where we have certain XQuery modules and we want to
know if there is a way to load a module into BaseX at Run-time?


https://docs.basex.org/wiki/XQuery_Module#xquery:parse-uri seems to
allow that.


The W3C library also defines
https://www.w3.org/TR/xpath-functions/#func-load-xquery-module but I
don't think BaseX supports that.



Re: [basex-talk] Stack overflow with random-number-generator

2020-05-11 Thread Martin Honnen

On 11.05.2020 23:33, Joe Wicentowski wrote:

I found a version that works.  In the original version I must not have
been using tail recursion correctly.  Here is the version that works.
Can anyone explain why the first version doesn't properly trigger tail
recursion?


No, but I think you can also apply fold-left

fold-left(
  1 to 2000,
  random-number-generator(),
  function($a, $i) { head($a)?next(), head($a)?number, tail($a) }
) => tail() => count()

instead of setting up your own tail recursive functions.




Re: [basex-talk] analyze-string

2020-04-23 Thread Martin Honnen


On 23.04.2020 15:40, Graydon Saunders wrote:

So if I create a query in the BaseX 9.3.2 GUI, thus:

declare function local:processMatch($in as text(),$matchPattern as
xs:string) as item()+ {
  let $search as element() :=
analyze-string(normalize-space($in),$matchPattern)
  return $search
};

let $example := These are a bunch of words, and some of the
words are special words.

for $text in $example//text()
          return local:processMatch($text,'bunch|special')

I get:
http://www.w3.org/2005/xpath-functions;>
  These are a 
  bunch
   of words, and some of the words *are*

http://www.w3.org/2005/xpath-functions;>
  special

http://www.w3.org/2005/xpath-functions;>
  words.


The trailing space after the *are* in the second fn:non-match element
is gone.

Should that happen?  Can I make it stop happening by invoking the
function differently?



Isn't your use of normalize-space in the function causing this? Why do
you need that?


Re: [basex-talk] How to apply array:for-each on an array of arrays?

2020-03-31 Thread Martin Honnen

On 31.03.2020 18:32, Ben Engbers wrote:

Hi,

For (my personal) clarity, I have split up the original function in two
parts:

declare function local:step_one($nodes as node()*) as array(*)*
{
   let $text := for $node in $nodes
  return $node/text() =>
  tokenize() => distinct-values()
   let $idf := $text   =>
  tidyTM:wordCount_arr()
   return $idf
};

In local:step_one(), I first create a sequence with the distinct tokens
for each $node. All the sequences are joined in $text.
I then call wordCount_arr to count the occurences of each word in $text:

declare function tidyTM:wordCount_arr(
   $Words as xs:string*)
   as array(*) {
for $w in $Words
   let $f := $w
   group by $f
   order by count($w) descending
return ([$f, count($w)])
} ;

I would say that tidyTM:wordCount_arr returns a sequence of arrays but I
am not certain if I have specified the correct return-type?


Reading the code I agree that the return type seems to be a sequence of
arrays but therefore I wonder why you don't get a similar error as later
on with declaring
  array(*)
and not
  array(*)*


Calling local:step_one(tidyTM:remove_Stopwords($nodes, "Stp", $Stoppers))
returns:
["probleem", 703]
["opgelost.", 248]


I had hoped that calling  the following local:wordFreq, would add the
idf to each element but instead I get an error

declare function local:wordFreq_idf($nodes as node()*)  as array(*)
{
   let $count := count($nodes)
   let $idf := local:step_one($nodes)
   let $result := for-each( $idf,
 function($z) {array:append ($z, math:log($count div $z(2) ) ) } )
   return $result
};
[XPTY0004] Cannot promote (array(xs:anyAtomicType))+ to array(*): $idf
:= ([ "probleem", 703 ], [ "opgelost.", 248 ], ...).


The message tries to tell you that the declared return type
  array(*)
is a single array while the function returns a (non-empty) sequence of
arrays so using
  declare function local:wordFreq_idf($nodes as node()*)  as array(*)*
would remove that error.

To insert the third value into each array I think you want

  let $result := $idf ! array:append(., math:log($count div .(2) ))


Re: [basex-talk] How to apply array:for-each on an array of arrays?

2020-03-31 Thread Martin Honnen

Am 30.03.2020 um 23:16 schrieb Ben Engbers:

Hi,

In textmining, the 'idf' or inverse document frequency is defined as
idf(term)=ln(ndocuments / ndocuments containing term). I am working on a
function that should return this idf.

This function:

declare function local:wordFreq_idf($nodes as node()*) as array(*) {
   let $count := count($nodes)
   let $text := for $node in $nodes
  return $node/text() => tokenize() => distinct-values()
  let $idf := $text   => tidyTM:wordCount_arr()
   return $idf
};

returns:

["probleem", 703]
["opgelost.", 248]
["dictu", 235]
["opgelost", 217]
["medewerker", 193]
...


So does the working function return a sequence of arrays? That doesn't
match the
  as array(*)
return type declaration, it seems.

What does tidyTM:wordCount_arr() return, a single array (of atomic items)?






Re: [basex-talk] collection('/test-db-1/bib')//Q{}libro versus collection('/test-db-1/bib')//libro

2020-03-30 Thread Martin Honnen

Am 29.03.2020 um 16:26 schrieb Martin Honnen:

Using BaseX 9.3.2, why does a query

   collection('/test-db-1/bib')//Q{}libro

return 6 items while

   collection('/test-db-1/bib')//libro

gives 0 items?

If I run

collection('/test-db-1/bib')//Q{}libro, collection('/test-db-1/bib')//libro

the info window shows


Compiling:
- rewrite fn:collection([uri]) to document-node() item:
collection("/test-db-1/bib") -> db:open-pre("test-db-1", 1202)
- merge steps: descendant::element(libro)
- rewrite fn:collection([uri]) to document-node() item:
collection("/test-db-1/bib") -> db:open-pre("test-db-1", 1202)
- remove step without results: element(libro)
- rewrite iter step to empty sequence: element(libro) -> ()
- rewrite cached path to empty sequence: db:open-pre("test-db-1",
1202)/descendant-or-self::node()/() -> ()
- rewrite expression list to iter path: (db:open-pre("test-db-1",
1202)/descendant::element(libro), ()) -> db:open-pre("test-db-1",
1202)/descendant::element(libro)
Optimized Query:
db:open-pre("test-db-1", 1202)/descendant::element(libro)
Query:
collection('/test-db-1/bib')//Q{}libro, collection('/test-db-1/bib')//libro
Result:
- Hit(s): 6 Items
- Updated: 0 Items
- Printed: 1455 b
- Read Locking: test-db-1
- Write Locking: (none)


It seems the problems occurs if I have one document in the db that has
elements in a namespace and one with elements in no namespace.

So if there is only one document with no namespaces then both
collection('/test-db-3/ex2')//foo and
collection('/test-db-3/ex2')//Q{}foo select the `foo` elements in no
namespace but if there is a document using a namespace as well in the db
then collection('/test-db-3/ex2')//foo does not select the `foo`
elements in no namespace.


Are there any db/namespace related settings in BaseX that cause that
behaviour?



[basex-talk] collection('/test-db-1/bib')//Q{}libro versus collection('/test-db-1/bib')//libro

2020-03-29 Thread Martin Honnen

Using BaseX 9.3.2, why does a query

  collection('/test-db-1/bib')//Q{}libro

return 6 items while

  collection('/test-db-1/bib')//libro

gives 0 items?

If I run

collection('/test-db-1/bib')//Q{}libro, collection('/test-db-1/bib')//libro

the info window shows


Compiling:
- rewrite fn:collection([uri]) to document-node() item:
collection("/test-db-1/bib") -> db:open-pre("test-db-1", 1202)
- merge steps: descendant::element(libro)
- rewrite fn:collection([uri]) to document-node() item:
collection("/test-db-1/bib") -> db:open-pre("test-db-1", 1202)
- remove step without results: element(libro)
- rewrite iter step to empty sequence: element(libro) -> ()
- rewrite cached path to empty sequence: db:open-pre("test-db-1",
1202)/descendant-or-self::node()/() -> ()
- rewrite expression list to iter path: (db:open-pre("test-db-1",
1202)/descendant::element(libro), ()) -> db:open-pre("test-db-1",
1202)/descendant::element(libro)
Optimized Query:
db:open-pre("test-db-1", 1202)/descendant::element(libro)
Query:
collection('/test-db-1/bib')//Q{}libro, collection('/test-db-1/bib')//libro
Result:
- Hit(s): 6 Items
- Updated: 0 Items
- Printed: 1455 b
- Read Locking: test-db-1
- Write Locking: (none)


Re: [basex-talk] Deactivate JSON escape

2020-02-26 Thread Martin Honnen

Am 27.02.2020 um 08:29 schrieb Johannes Bauer:

Am 27.02.2020 um 08:25 schrieb Johannes Bauer:

Am 27.02.2020 um 08:15 schrieb Martin Honnen:

Am 27.02.2020 um 07:49 schrieb Johannes Bauer:

I'm trying to deactivate the escaping of characters for JSON
serialization.

It does not work with this:

let $json := http://www.w3.org/2005/xpath-functions;>
    http://some.url/path/to/somewhere
return json:serialize($json, map {'format' : 'basic', 'escape': 'no'})

Output:
{
  "url":"http:\/\/some.url\/path\/to\/somewhere"
}


Does

serialize(http://www.w3.org/2005/xpath-functions;>
    http://some.url/path/to/somewhere,
  map { 'method' : 'json', 'use-character-maps' : map { '/' : '/'}})

do what you want?


unfortunately no, I still get the "\/" in the output with:

serialize(
  http://www.w3.org/2005/xpath-functions;>
    http://some.url/path/to/somewhere
  ,
  map {'method': 'json', 'use-character-maps': map { '/' : '/'},
'json': map {'format' : 'basic'}}
)




http://www.w3.org/2005/xpath-functions;>
    http://some.url/path/to/somewhere
=> xml-to-json()
=> parse-json()
=> serialize(map { 'method': 'json', 'use-character-maps' : map { '/' :
'/' }})


gives the JSON with unescaped slashes for me in BaseX and Saxon. Not
sure there is a more compact way, either BaseX specific or for XQuery in
general, to achieve this. I am sure Christian can tell you.




Re: [basex-talk] Deactivate JSON escape

2020-02-26 Thread Martin Honnen

Am 27.02.2020 um 07:49 schrieb Johannes Bauer:

I'm trying to deactivate the escaping of characters for JSON
serialization.

It does not work with this:

let $json := http://www.w3.org/2005/xpath-functions;>
    http://some.url/path/to/somewhere
return json:serialize($json, map {'format' : 'basic', 'escape': 'no'})

Output:
{
  "url":"http:\/\/some.url\/path\/to\/somewhere"
}


Does

serialize(http://www.w3.org/2005/xpath-functions;>
    http://some.url/path/to/somewhere,
  map { 'method' : 'json', 'use-character-maps' : map { '/' : '/'}})

do what you want?



Re: [basex-talk] Dynamic evaluation?

2020-02-26 Thread Martin Honnen

Am 26.02.2020 um 12:42 schrieb Ben Engbers:

Hi,

I want to declare a function that can operate on various elements of a
record. It should be possible to pass the element-name as parameter to
the function.

I tried this:

declare function local:cloudWords(
   $Veld as xs:string
) as xs:string*
{
   let $base := collection('IncidentRemarks/Incidentsv')/csv/record
   let $txt := string-join( $base/$Veld/text(), " ")
   let $words := tokenize($txt,'(\s|[,.!:;]|[n][b][s][p][;])+')
   return ($words)
};

let $retValue := local:cloudWords("INC_RM")
return $retValue

But I get this error:
[XPTY0019] text(): node expected, xs:string found: "INC_RM".

Should I use xquery:eval to transform "$base/$Veld/text()" into
"$base/INC_RM/text()"


For such simple cases with an element name it seems

  $base/*[local-name() = $Veld]


suffices.




Re: [basex-talk] how to nest tags using a conditional

2020-02-19 Thread Martin Honnen

Am 19.02.2020 um 15:08 schrieb thufir:

How can I start a new "record" and then nest tags in that record?


but I'm getting output like:


  
  if (matches($line, "[0-9]"))
  then people
  else people
  
  
  if (matches($line, "[0-9]"))
  then joe
  else joe
  
..

wheras I just want output like:


  joe
  123



the query:

xquery version "3.0";


{
for $line in db:open("foo.txt")//text()
return
    



Nest any contained expression in further curly braces

  {


  if (matches($line, "[0-9]"))
  then {$line}
  else {$line}



}



}










Re: [basex-talk] how to store a result in a database?

2020-02-19 Thread Martin Honnen

Am 19.02.2020 um 14:36 schrieb thufir:

While I can certainly output the result to a file, and then add to a
database, how would I actually send the result directly to a database?

xquery version "3.0";


{
for $line in db:open("people.json")//text()
return
  if (matches($line, "[0-9]"))
  then {$line}
  else {$line}
}




See http://docs.basex.org/wiki/Database_Module#db:add, you seem to want

  db:add("people.all",

   
{
for $line in db:open("people.json")//text()
return
  if (matches($line, "[0-9]"))
  then {$line}
  else {$line}
}


)


that is, you simply want to pass your query result as the second
argument to the db:add function.



Currently I'm running it like so:

thufir@dur:~/flwor/people.json$
thufir@dur:~/flwor/people.json$ basex all.xq > all.xml
thufir@dur:~/flwor/people.json$
thufir@dur:~/flwor/people.json$ basex
BaseX 9.0.1 [Standalone]
Try 'help' to get more information.
>
> create database people.all
Database 'people.all' created in 234.74 ms.
>
> set parser xml
PARSER: xml
>
> add all.xml
Resource(s) added in 377.43 ms.
>
> exit
Have fun.
thufir@dur:~/flwor/people.json$


but that's a bit cumbersome.




thanks,

Thufir





Re: [basex-talk] filtering NaN from a sequence

2020-02-02 Thread Martin Honnen

Am 03.02.2020 um 01:22 schrieb Graydon Saunders:

for $value in $xmlReport/csv/record/Payment_Amount/number()
  where ???
  return $value


Can you live with

for $value in $xmlReport/csv/record/Payment_Amount
  where $value castable as xs:double
  return xs:double($value)

?




Re: [basex-talk] Parsing MusicXML files

2019-12-29 Thread Martin Honnen

Am 29.12.2019 um 16:34 schrieb Joe Curtis:

return $word, $p, $m


I think you want

  return ($word, $p, $m)



Re: [basex-talk] Weird: mixed content trimmed unexpectedly

2019-12-09 Thread Martin Honnen

On 09.12.2019 16:51, Omar Siam wrote:


Probably there is an option
(CHOP?) that one can set to tell BaseX not to trim whitespace at the
edges of text nodes.


Yes, see http://docs.basex.org/wiki/Options#XML_Parsing


Re: [basex-talk] Issue with years-from-duration!?

2019-12-06 Thread Martin Honnen

Am 06.12.2019 um 11:32 schrieb Martin Honnen:

Am 06.12.2019 um 11:23 schrieb France Baril:



The following function returns P4511D: 0 but I expect P4511D: 12
Bug or bad usage?

let $d1 := xs:date('2007-07-31')
let $d2 := xs:date('2019-12-06')
let $duration := $d2 - $d1
let $years := years-from-duration($duration)
return $duration || ': ' || $years




The spec
https://www.w3.org/TR/xpath-functions/#func-years-from-duration says
"If|$arg|is an|xs:dayTimeDuration|the function returns 0.".



As a workaround, see
https://www.oxygenxml.com/archives/xsl-list/200601/msg00446.html which
tries to compute the years from the dayTimeDuration.


Re: [basex-talk] Issue with years-from-duration!?

2019-12-06 Thread Martin Honnen

Am 06.12.2019 um 11:23 schrieb France Baril:



The following function returns P4511D: 0 but I expect P4511D: 12
Bug or bad usage?

let $d1 := xs:date('2007-07-31')
let $d2 := xs:date('2019-12-06')
let $duration := $d2 - $d1
let $years := years-from-duration($duration)
return $duration || ': ' || $years




The spec https://www.w3.org/TR/xpath-functions/#func-years-from-duration
says "If|$arg|is an|xs:dayTimeDuration|the function returns 0.".





Re: [basex-talk] simplest possible FLOWR specifying a database

2019-10-12 Thread Martin Honnen

Am 12.10.2019 um 10:11 schrieb thufir:

nevermind, it's:

let $db := db:open("com.w3schools.books")
return $db/bookstore

I thought it was unusual because of db:open.




You would not even need the "let .. return", if you simply want a short
expression you can also use

  db:open("com.w3schools.books")/bookstore




[basex-talk] Does BaseX used as a command line XQuery processor build a full tree of an input document passed with -i option?

2019-10-02 Thread Martin Honnen



If I use BaseX (9.2.4) simply as an XQuery 3.1 processor from the
command line with e.g.

basex.bat -i input.xml query.xq

does BaseX then first always parse the input.xml into an XDM tree,
meaning if I use huge input documents that way I can run easily run out
of memory?

Or does that depend on the type of query or some other settings?

I was wondering whether a "tumbling window" based split algorithm like

declare namespace output =
"http://www.w3.org/2010/xslt-xquery-serialization;;

declare option output:method 'xml';
declare option output:indent 'yes';

declare variable $chunk-size as xs:integer external := 500;

for tumbling window $chunk in /*/*
start at $sp when $sp mod $chunk-size = 1
count $p
return
    put(document {
    element { node-name(head($chunk)/..) } {
    $chunk
    }
    }, 'xquery-split-result-' || $p || '.xml')

would run/work without memory problems for huge inputs.





Re: [basex-talk] XQuery Update and Namespace Manipulation

2019-09-10 Thread Martin Honnen

On 10.09.2019 03:50, Andreas Mixich wrote:


adding to my last email: of course, this way I still did not solve
addition of more namespaces. Any ideas on that?

modify insert node namespace {"foo"} {"foobar"} into $c/self::node()

Because, even if I reconstruct the node completely, with the
non-updating expressions, I would not know any other syntax, that would
match the purpose.


Let's hope that Christian or others can give you some insight on that, I
can't get any handle on how to figure where/how the XQuery update spec
or implementations allow deletion or insertion of namespaces. I found
one question on StackOverflow answered by Christian that suggested that
deletion is not possible with XQuery update.



Re: [basex-talk] XQuery Update and Namespace Manipulation

2019-09-09 Thread Martin Honnen

On 09.09.2019 20:35, Martin Honnen wrote:

On 09.09.2019 20:30, Andreas Mixich wrote:

Hi,

copy $c := ipsum dolor sit amet
modify insert node namespace {"lipsum"} {"lorem-ipsum"} into $c
return $c

Expected result:

ipsum dolor sit
amet



The namespace is part of the name of a node so you need to rename the
node(s) in a namespace if you want to change the namespace


Your example would be

copy $c := ipsum dolor sit amet
modify rename node $c as QName("lorem-ipsum", "lipsum:" || local-name($c))
return $c




Re: [basex-talk] XQuery Update and Namespace Manipulation

2019-09-09 Thread Martin Honnen

On 09.09.2019 20:30, Andreas Mixich wrote:

Hi,

copy $c := ipsum dolor sit amet
modify insert node namespace {"lipsum"} {"lorem-ipsum"} into $c
return $c

Expected result:

ipsum dolor sit amet



The namespace is part of the name of a node so you need to rename the
node(s) in a namespace if you want to change the namespace, see
https://www.w3.org/TR/xquery-update/#id-rename saying

The effects of a rename expression are limited to its target node.
Attributes and descendants of the target node are not affected. If a
global change of names or namespaces is intended, some form of explicit
iteration must be used. The following example illustrates such a global
change. The example operates on the node bound to variable $root and all
its attributes and descendants, changing all QNames with the prefix abc
to have a new prefix xyz and a new namespace URI http://xyz/ns.

for $node in $root//abc:*
let $localName := fn:local-name($node),
$newQName := fn:concat("xyz:", $localName)
return (
   rename node $node as fn:QName("http://xyz/ns;, $newQName),
   for $attr in $node/@abc:*
   let $attrLocalName := fn:local-name($attr),
   $attrNewQName := fn:concat("xyz:", $attrLocalName)
   return
  rename node $attr as fn:QName("http://xyz/ns;, $attrNewQName)
)


Re: [basex-talk] xs:string("<")

2019-08-25 Thread Martin Honnen

Am 25.08.2019 um 14:16 schrieb Giuseppe G. A. Celano:



I am wondering why xs:string("&") is not possible, but
xs:string("<") is (although XML does not allow both ). Is there any
reason? Thanks.




You are allowed to use some predefined entity references and to use
character references in string literals, see
https://www.w3.org/TR/xquery-31/#prod-xquery31-StringLiteral which defines

[222]       StringLiteral       ::=       ('"' (PredefinedEntityRef |
CharRef | EscapeQuot | [^"&])* '"') | ("'" (PredefinedEntityRef |
CharRef | EscapeApos | [^'&])* "'")

so you can use the ampersand as a meta character for e.g. `` and
e.g. ``, on the other hand, to use it literally, you need some
escape mechanism in the form of ``.

Inside XML the angle brackets are needed for markup but that is not the
case inside of a string literal so you can use them freely in there.



Re: [basex-talk] Declaring namespaces in xquery:eval call

2019-08-09 Thread Martin Honnen

On 09.08.2019 20:50, Buddy Kresge wrote:

I am trying to do something like xquery:eval(“some:function()”), and
when I go to execute I get “[XPST0081] No namespace declared for
‘some:function’


Can't you just declare the proper namespace in a prolog of the code you
pass to eval e.g.

 xquery:eval("declare namespace some = 'http://example.com';
some:function()")

?



Re: [basex-talk] comment()

2019-08-08 Thread Martin Honnen

Am 08.08.2019 um 08:46 schrieb Marc:

I use very often the comment() with XSLT, and I confuse it with the
"comment" literal of XQuery !



But even in XSLT the use of "comment()" is only for selecting/matching
comment nodes (or for declaring a type), not for creating/constructing
them. In XSLT you use the xsl:comment instruction to construct a comment
node.



Re: [basex-talk] comment()

2019-08-07 Thread Martin Honnen

On 07.08.2019 18:52, Marc wrote:


I want to write a comment in the xml I produce with my XQuery.
I try to use the comment() function, but each time I want to put
something inside the () i have a syntax error.


If you want to create a comment node computed by an expression use
  comment { expression }

see https://www.w3.org/TR/xquery-31/#doc-xquery31-CompCommentConstructor

So
  comment { $r }
seems to be what you want to do.


Re: [basex-talk] Coding help

2019-08-05 Thread Martin Honnen

Am 05.08.2019 um 08:41 schrieb Greg Kawchuk:

Hi everyone,
I'm wondering if someone could provide what I think is a brief script
for a scientific project to do the following.
The goal is to identify XML documents from a very large collection
that would be too big to load into a database all at once.

Here is how I see the functions provided by the code.
1. In the script, the user could enter the path of the target folder
(with millions of XML documents).
2. In the script, the user would enter the number of documents to load
into a database at a given time (i =. 1,000) depending on memory
limitations.
3. The code would then create a temporary database from the first (i)
xml files in the target folder.
4. The code would then search the 1000 xml documents in the database
for a pre-defined text string.



What kind of search is that exactly? Does it depend on any database
related features at all or can't you just use BaseX as a standalone
XQuery processor?


5. If hits exist for the text string, the code would write those
documents to a unique XML file.



What kind of structure would that unique file have, simply

  {collection('foo')[1 to 1000][condition]}


6. Clear the database.
7. Read in the next 1000 files (or remaining files in the folder).
8. Return to #4.

There would be no need to append XML files in step 5. The resulting
XML files could be concatenated afterwards.
Thank you in advance. If you have any questions, please feel free to
email me here.






Re: [basex-talk] Quickest way to parse a DomSource

2019-07-22 Thread Martin Honnen

Am 22.07.2019 um 11:32 schrieb Marco Lettere:



I have to access portions of the XML representation of the BPMN file
by binding the engine's API.

The closest that I can get to a standard XML representation is
currently a javax.xml.transform.dom.DOMSource.

What is the shortest way to transform (in XQuery) this DomSource to a
BaseX representation of the Document in order to query it?



The XQJ API seems to have a method

http://xqj.net/javadoc/javax/xml/xquery/XQDynamicContext.html#bindDocument(javax.xml.namespace.QName,%20javax.xml.transform.Source,%20javax.xml.xquery.XQItemType)

 to allow passing in a java.xml.transform.Source so that seems at least
one way to deal with a DOMSource. But it happens on the Java side and is
tied to that particular XQJ API.





Re: [basex-talk] Query filter by attributes with Colons

2019-07-15 Thread Martin Honnen

On 15.07.2019 16:34, Jordan Castillo wrote:


I am noticing that my queries aren't working when I check the value of
an attribute who has a colon in the name field. Here is an example:

1: Yields no results
   let $begin := db:open($documentName)
   return $begin//packagedElement[@name="auxiliaryResource" and
@xmi:id="_12_1_8f90291_1173963323875_662612_98"]

2: Yields no results
   return
$begin//packagedElement[@xmi:id="_12_1_8f90291_1173963323875_662612_98"]

3: Yields expected result:
   return $begin//packagedElement[@name="auxiliaryResource"]

Example of element I am searching for here:



What is the namespace declared for the prefix xmi?
You need to declare that in the XQuery code as well.



Re: [basex-talk] Serialize to XHTML 5?

2019-05-04 Thread Martin Honnen

Am 04.05.2019 um 12:41 schrieb Andreas Mixich:

let $doc := Example
TitleParagraph
return serialize($doc, map{"method":"xhtml", "version":"5.0"})


Use

  serialize($doc, map{"method":"xhtml", "html-version":"5.0"})


Note however that XHTML usually means the HTML elements are in the XHTML
namespace i.e.

let $doc := Example
TitleParagraph
return serialize($doc, map{"method":"xhtml", "html-version":"5.0"})



Re: [basex-talk] Func def & performance: element()* vs item()*

2019-04-11 Thread Martin Honnen

Am 11.04.2019 um 00:09 schrieb Chuck Bearden:

BaseX is a great tool for analyzing & characterizing large amounts of
XML data. I have used it both at work and on personal projects. I hope
the following observation is useful.

When I define a function that recurs over a sequence of elements in
order to build a map of element name counts, I find that when I
specify the type of the element sequence as 'element()*', the function
runs so slowly that I give up after 5 minutes or so. But when I
specify the type as 'item()*', it finishes in 40 seconds or less.
Here's an example:

-begin code snippet-
declare namespace local="w00fw00f";
declare function local:count($elems as element()*, $elem_counts as map(*))
 as map(*) {
 let $elem := head($elems),
 $elem_name := $elem/name(),
 $elems_new := tail($elems),
 $elem_name_count := if (map:contains($elem_counts, $elem_name))
 then map:get($elem_counts, $elem_name) + 1
 else 1,
 $elem_counts_new := map:put($elem_counts, $elem_name, $elem_name_count)
 return if (count($elems_new) = 0)
 then $elem_counts_new
 else local:count($elems_new, $elem_counts_new)
};

let $coll := collection('pure_20190402'),
 $elems := $coll/result/items/*,
 $elem_names_map := local:count($elems, map {})



It seems that task to build the map can also be solved with grouping:

let $elem_names_map := map:merge(
for $item in $coll/result/items/*
group by $name := name($item)
return map { $name : count($item) }
)


Not sure whether that improves performance.



Re: [basex-talk] Two questions on use of the serialize function and character maps

2019-04-05 Thread Martin Honnen

On 05.04.2019 17:50, Christian Grün wrote:


Out of interest: What are your use cases for the adaptive serialization
method?


The question about the character map support arose in the context of
trying to create an XPath 3.1 character map itself in XSLT and serialize
it in a way that it could be inserted into an XSLT attribute with XPath
code.


Re: [basex-talk] BigInteger

2019-04-05 Thread Martin Honnen

Am 05.04.2019 um 11:15 schrieb Andre Bovy:

Hi Chistian,

I am trying to use a very Big Integer in BaseX (9.1.2)

With this value :
declare namespace BigInteger = "java:java.math.BigInteger";

BigInteger:new("12345678901234567890”)

I received : Cannot convert xs:string to xs:integer:
"12345678901234567890”.

The java method that I used returns a BigInteger, but I just need the
value as a String.




If you have the BigInteger returned from your Java method and want it as
an XQuery string try

  let $s as xs:string := BigInteger:toString($valueFromJavaMethod)

or

   let $s as xs:string := $valueFromJavaMethod => BigInteger:toString()


e.g. a complete example that works for me with BaseX 9 is


declare namespace BigInteger = "java:java.math.BigInteger";

let $s as xs:string := BigInteger:TEN() => BigInteger:toString()
return $s


Not sure about that problem with the constructor, with Saxon


declare namespace BigInteger = "java:java.math.BigInteger";

let $s as xs:string := BigInteger:new("12345678901234567890") =>
BigInteger:toString()
return $s


runs fine as well but with BaseX I get the error you mentioned.




Re: [basex-talk] Two questions on use of the serialize function and character maps

2019-04-02 Thread Martin Honnen

On 02.04.2019 22:37, Christian Grün wrote:


What's your view of adaptive serialization of map(xs:string,xs:string)
and a character map, should the character map be applied to the map's
key and value string values?


My general view on the adaptive serialization method is that I would
have loved it to become what the name implies (adaptive: best fit for
the type that’s to be serialized). Instead, it has more or less become
a debugging method, and many details have eventually been left to the
implementation. As a consequence, we don’t have real use cases for
this method, but if it’s used for debugging, it might be better if
character maps were ignored, because they could easily create output
that’s difficult to reuse.


For XSLT 3 (which shares serialization methods with XQuery) Michael Kay
has committed
https://github.com/w3c/xslt30-test/commit/21685399a560de67391707cbf5cbff536bcf5139
to the XSLT test suite where the defined test results suggest that
character maps are to be taken into account for strings with the
adaptive output method. And Saxon 9.9's AdaptiveEmitter
https://saxonica.plan.io/issues/4187#note-7 has been "adapted" to use a
character map "when outputting strings as atomic values". Guess that
means that Saxon 9.9 in the next maintenance release will use that code
also for XQuery serialization.



Re: [basex-talk] Two questions on use of the serialize function and character maps

2019-04-02 Thread Martin Honnen

Hi Christian,

On 02.04.2019 14:36, Christian Grün wrote:



1) Is there any way to provide the "use-character-maps" parameter
supplied the XPath 3.1 way with a second argument to "serialize" as a map:
   serialize("a,b", map { 'method' : 'text', 'use-character-maps' :
map { "'" : "apos;" }})


In BaseX, values of the fn:serialize map argument are restricted to
strings (this still differs from the requirements of the official
specification).



Are there plans to remove the restrictions on string arguments?
It is hard writing standard XQuery 3.1 when one implementation (BaseX)
wants
  map { 'indent' : 'yes' }
and another like Saxon
  map { 'indent' : true() }


As character map handling is a special case, I have
extended our code, and your query should now be evaluated as expected.


Thanks, works fine in the snapshot.



2) When I try the XPath 3.0 way of providing the serialization
parameters as an XML element I also get an error:


Until now, character maps were only correctly parsed when specified in
parameter documents in the query prolog. I have fixed this as well.


Great.


Saxon 9.9 and Altova 2018 run that example without giving an error
(although not with the same serialization result, but that is a
different issue).


This might be due to the somewhat fuzzy rule in the spec, which states
that the "use-character-maps parameter is directly applicable to the
Adaptive output method only as elsewhere specified." [1]


What's your view of adaptive serialization of map(xs:string,xs:string)
and a character map, should the character map be applied to the map's
key and value string values?

It seems BaseX doesn't do that.

The spec gives the sentence you cited but also "Character maps are
applied (a) when nodes are serialized using the XML output method, and
(b) to any value represented as a string enclosed in quotation marks".

I am not sure whether that is meant to be applied to string values
inside maps.


[basex-talk] Two questions on use of the serialize function and character maps

2019-03-31 Thread Martin Honnen



I am struggling to use the "serialize" XPath 3.1 function as specified
by the W3C with BaseX 9.1.2:

1) Is there any way to provide the "use-character-maps" parameter
supplied the XPath 3.1 way with a second argument to "serialize" as a map:
 serialize("a,b", map { 'method' : 'text', 'use-character-maps' :
map { "'" : "apos;" }})

I get an error saying
  [SEPM0017] Invalid 'use-character-maps' value 'map { "'":
"apos;" }'; must be a string.

2) When I try the XPath 3.0 way of providing the serialization
parameters as an XML element I also get an error:

When I run

declare namespace output =
"http://www.w3.org/2010/xslt-xquery-serialization;;

declare option output:method "text";

serialize(
  (
',
"'",
map {
  "Ä":"\'C4",
  "Ö":"\'D6",
  "Ü":"\'DC",
  "ß":"\'DF",
  "ä":"\'E4",
  "ö":"\'F6",
  "ü":"\'FC"
}
  ),
  http://www.w3.org/2010/xslt-xquery-serialization;>


   

  
)

in BaseX it tells me
  [SEPM0017] Character map 'character-map=,' is not defined.


Saxon 9.9 and Altova 2018 run that example without giving an error
(although not with the same serialization result, but that is a
different issue).


Re: [basex-talk] Higher order functions in XSLT

2019-03-28 Thread Martin Honnen

Am 28.03.2019 um 11:48 schrieb nikos dimitrakas:

Hi!

Is there something in BaseX that prohibits using higher order
functions in XSLT (called with xslt:transform)?

for-each($somenodes, function($q) { string($q) })

and

for-each($somenodes, string#1)

both work in XQuery in BaseX, but when I use the same call in an XSLT
that I call with xslt:transform, I get the following message

XPST0003: Inline functions require support for higher-order-functions,
which needs Saxon-PE or higher. I am using Saxon EE 9.9.1.2 (also
tried PE 9.9.1.2)

The XSLT works fine if I run it with Saxon directly without using
BaseX and the function xslt:transform. Is there something I can do to
get this to work, or is this out of my control?




Do you get other Saxon EE or PE only features to work when using it from
BaseX? It might be that your Saxon EE license is not found and in that
case I think Saxon EE or PE fall back to only offer HE features.

So make sure the Saxon license file is on the class path.




Re: [basex-talk] following-sibling axis

2019-02-26 Thread Martin Honnen

Am 26.02.2019 um 18:52 schrieb Mark Bordelon:
A follow-up:  starting basex -w does NOT seem to solve completely my 
issue after all. Real data (more complicated than the simplified 
example) still does not query correctly: text nodes from after later 
elements are displayed in the place of null text nodes.

I’ll try to get a better example, still simplified, that shows this.



Just to make sure, if the data is already in the database and has been 
inserted with the default whitespace chopping turned on, the result you 
get for your sample is correct.


So at least in my understanding the only way to get the result you want 
is to make sure the original input XML is inserted again into the 
database, this time with chopping turned off.






Re: [basex-talk] following-sibling axis

2019-02-26 Thread Martin Honnen

Am 26.02.2019 um 07:54 schrieb Mark Bordelon:
But I have a question about some behavior I am seeing in the 
*following-sibling* axis that does not seem logical to me.


Here is the data stored in basex:
> xquery /text[@id='test']

  
Aa
B
Cc
  


Here is the query on that data:
> *xquery /text[@id='test']//word/concat(text(), ' ', 
normalize-space(./following-sibling::text()[1]))*

A a
B *c*
C c



I think the result you get is caused by whitespace chopping during XML 
parsing, seems to be the default, see 
http://docs.basex.org/wiki/Command-Line_Options


|-w| 	Toggles whitespace chopping of XML text nodes. By default, 
whitespaces will be chopped.






Re: [basex-talk] following-sibling axis

2019-02-25 Thread Martin Honnen

Am 26.02.2019 um 07:54 schrieb Mark Bordelon:

Guten Tag,
Love my basex, have been using it for years. I particularly love being 
able to have access to all the powerful 2.0 syntax.
But I have a question about some behavior I am seeing in the 
*following-sibling* axis that does not seem logical to me.


Here is the data stored in basex:
> xquery /text[@id='test']

  
Aa
B
Cc
  




How did you store/parse it, in particular did you use any options to 
strip white space?



Here is the query on that data:
> *xquery /text[@id='test']//word/concat(text(), ' ', 
normalize-space(./following-sibling::text()[1]))*

A a
B *c*
C c

The same query run in 
https://www.freeformatter.com/xpath-tester.html in the same xml gives 
me the predictable result that I need:

String='A a’
String='B ‘
String='C c'


Is there any way to alter my query to get the above result in basex? I 
imagine that this an xpath1.0 vs xpath2.0 issue.




That path with a function call in the (last) step isn't allowed in XPath 
1.0 at all.





Re: [basex-talk] Reg : Xquery performence

2018-11-28 Thread Martin Honnen

Am 28.11.2018 um 10:45 schrieb chandra Sekhar:


Dear basex,

Please find attachment for sample xml,Like sample xml we are added 
multiple xml's to the collection .Below query is my XQuery ,It is 
taking huge time,Can we optimize this query.



My collection size is nearly 1.5 GB



let $entriesDisplay := 'Display All'
 let $Rows := 
(collection("752150_Voice_OCTOBER-18_Billed")/SUBCUSTBRK[AccNo[@NO = 
(9800964)]][DOB >='2018-10-01'   and DOB <='2018-10-31'][ServInfo!=0])

 let $accNo := "9800964"
 let $accWiseTags := $Rows[AccNo[@NO = $accNo]]
 for $servNos in distinct-values($accWiseTags/CONN/@NO)
 let $eachRow := $accWiseTags[CONN[@NO=$servNos]]
 return  $eachRow


Have you tried to use `group-by` e.g.

  for $r in $accWiseTags

  group by $no := $r/CONN/@NO

  return $r

?



Re: [basex-talk] fn:format-number() for german style numbers

2018-10-27 Thread Martin Honnen

Am 27.10.2018 um 08:39 schrieb Wiemer, Sebastian:



How do I format german style numbers e.g.: 1.000.00,99€ (for one 
million € and 99cents) ?

The following approach:

format-number(26825.8, '#.###,00')

yielded an error: [FODF1310] Invalid picture string: '#.###,00'.



See https://www.w3.org/TR/xquery-31/#id-decimal-format-decl

declare decimal-format local:de
  decimal-separator = "," grouping-separator = ".";
format-number(26825.8, '#.###,00', 'local:de')




[basex-talk] Should serialize function take "newline" : "\r\n" option in the map parameter into account?

2018-09-04 Thread Martin Honnen



When I run

contains(serialize("Line 1.Line 2.Line 3.", map { "method" : 
"text", "newline" : "\r\n" }), '')


in BaseX 9.0.2 (from the command line basex.bat or in the GUI) I get the 
result "false" while I expected "true".



Have I not provided the newline option correctly?




Re: [basex-talk] [XQUERY] Filter and paging with window clause

2018-08-28 Thread Martin Honnen

On 28.08.2018 11:04, Marco Lettere wrote:


here's a question related to XQuery, sorry for being slightly off-topic.

I'm struggling to find a way to combine the windowing clause and FLOWR 
in order to get a paged result of a subset of items which respect a 
given filter.


Of course I'm able to get this by first applying the filter to the whole 
input and then a second FLOWR for the windowing clause.


So what is the filter condition? What is the input sequence?

The closer I get is [1] which is not what I'd need because I get 
2,4,6,8,10 as result for page 1 but I'd really want 10 results per page 
thus 2,4,6,8,10,12,14,16,18,20.


Thanks for any help on this in the meanwhile I'll stick to my naive 
solution.


Marco.

[1]

let $page := 1
let $count := 10
return
   for tumbling window $w in (1 to 100)
   start $first at $s when ($s = 1 + ($page - 1) * $count)
   end $last at $e when ($e - $s = $count - 1)
   return
     $w ! (if (. mod 2 = 0 ) then . else ())



Can't you simply use the filter as a predicate on the expression you use 
in the windowing for clause?


Does

let $page-size := 10
for tumbling window $page in (1 to 100)[. mod 2 = 0]
  start at $sp when $sp mod $page-size = 1
  end at $np when ($np + 1) mod $page-size = 1
return {$page}

help?

It returns

2 4 6 8 10 12 14 16 18 20
22 24 26 28 30 32 34 36 38 40
42 44 46 48 50 52 54 56 58 60
62 64 66 68 70 72 74 76 78 80
82 84 86 88 90 92 94 96 98 100





Re: [basex-talk] XML well-formed error

2018-06-06 Thread Martin Honnen
I think the problem is that your XSLT generates a result fragment with 
several top level chapter elements, lacking a single root element 
containing the other elements.
So you need to change the stylesheet to create a single root element or 
someone with more BaseX inside skills needs to tell how to use and 
process the result of a stylesheet that is not a well-formed document 
but a fragment.


Am 06.06.2018 um 13:18 schrieb DK Singh:
it is getting transformed on oxygen, but in the basex GUI not getting 
transformed, my req is to transformed file has to be write on the file 
system, but on the Basex GUI not getting transformed


Regards
Dharmendra Kumar Singh

On Wed 6 Jun, 2018, 4:26 PM Andy Bunce, > wrote:


Hi Dharmendra Kumar,

When I run this in Oxygen, loading the result into an editor
window, I get the same message that BaseX  gives:

Description: The markup in the document following the root element
must be well-formed.
Start location: 1:68199
URL:

http://www.saxonica.com/html/documentation/javadoc/net/sf/saxon/trans/SaxonErrorCode.html#SXXP0003


Your transform is not generating a valid XML document.

Regards
/Andy

On 6 June 2018 at 11:07, DK Singh mailto:dharam.m...@gmail.com>> wrote:

Hi Christian for your reference i am attaching the XSLT and
XML which i am trying to transfom using BaseX GUI

QUERY
=

let $xml := fn:doc('D:\2018\VCLP-A2 - admin.xml')
let $xsl := fn:doc('D:\2018\DBK2BloomsburyDbk.xslt')
return  xslt:transform($xml,$xsl)

Error
==
Error:
Stopped at D:/2017/BLOOMSBURRY/testing-code/eBloomsbury/file,
3/23:
[FODC0002] "" (Line 1): The markup in the document following
the root element must be well-formed.

you can try out to simply run the query on BaseX GUI , i have
attached the XML and  XSLt

Regards
Dharmendra Kumar Sngh



On Wed, Jun 6, 2018 at 3:24 PM, Christian Grün
mailto:christian.gr...@gmail.com>>
wrote:

Hi
​
Dharmendra Kumar.

P
lease provide us with a little self-contained example (see
http://sscce.org/for more information).

​
Thanks in advance ;)
Christian



On Wed, Jun 6, 2018 at 11:53 AM, DK Singh
mailto:dharam.m...@gmail.com>> wrote:

Hi Christian,
i am running the simple query on Basex GUI

let $xml := fn:doc('D:\2018\VCLP-A2 - admin.xml')
let $xsl := fn:doc('D:\2018\DBK2BloomsburyDbk.xslt')
return xslt:transform($xml,$xsl)
Regards
​​
Dharmendra Kumar Singh

On Wed, Jun 6, 2018 at 2:49 PM, Christian Grün
mailto:christian.gr...@gmail.com>> wrote:

Hi ​Dhamendra Kumar,​

As usual,
​​
please provide us with a little example (see
http://sscce.org/ for more information).

​​
Thanks in advance,
Christian


On Wed, Jun 6, 2018 at 11:16 AM, DK Singh
mailto:dharam.m...@gmail.com>> wrote:

Hi All,
I have a XML file when i apply xslt using
xslt:transform function it is giving well
formed error, even i tried on BaseX UI using
xslt:transform function

[FODC0002] "" (Line 1): The markup in the
document following the root element must be
well-formed.

but when the same file i transform on the
oxygeng editor it getting transformed, can
anyone suggest what going wrong.
Regards
Dharmendra Kumar Singh










Re: [basex-talk] XSLT Module: feature request - XSLT 3.0 support

2018-04-09 Thread Martin Honnen

On 09.04.2018 19:14, Yitzhak Khabinsky wrote:

We have Saxon EE edition v.9.8.* licenses and are using XSLT stylesheets 
compliant with the  XSLT 3.0 standard.


Unfortunately, BaseX XSLT module currently supports up to XSLT 2.0 
standard only.


return xslt:processor(), xslt:version() yields the following:

*Saxon EE*

*2.0*

Though Saxon XSLT processor supports XSLT 3.0 standard.

XSLT 3.0 features are available in all Saxon editions.


For what it's worth, I have started BaseX with Saxon 9.8 EE on the class 
path and have run (using the xslt:transform-text function) an XSLT 3.0 
stylesheet  inspecting the various XSLT system-property() results and 
the results clearly indicate that Saxon runs as an XSLT 3.0 processor 
with all new XSLT 3.0 features it implements (like 
xsl:supports-dynamic-evaluation, xsl:supports-higher-order-functions, 
xsl:xpath-version as 3.1) so I don't know what the BaseX xslt:version() 
function does but I think it doesn't prevent you from running XSLT 3 
with BaseX.





Re: [basex-talk] XQuery 3.1/Build array of maps dynamically

2017-12-12 Thread Martin Honnen

On 12.12.2017 13:30, Hondros, Constantine (ELS-AMS) wrote:

I was already kicking myself for rushing and not providing a SCE! Please 
see the code below, and thanks.


declare option output:method 'json';

declare variable $authors := 

     

     Robert A

     Sanders

     

     

     Emily

     Chapel

     

;

map {

     "authors": [

   (for $b in $authors/author return

 map{"fn":$b/*:given-name/text(), "ln":$b/*:surname/text()})

     ]

}


I think to get the map structure from your earlier sample you want

declare option output:method 'json';



declare variable $authors := 



Robert A

Sanders





Emily

Chapel



;



map {

"authors": array{$authors/author!map{"fn" : data(given-name), "ln" 
: data(surname)}}




}

Result is

{
  "authors": [
{
  "ln": "Sanders",
  "fn": "Robert A"
},
{
  "ln": "Chapel",
  "fn": "Emily"
}
  ]
}


Re: [basex-talk] XPath generator

2017-11-17 Thread Martin Honnen

On 17.11.2017 15:06, Giuseppe Celano wrote:


I would like to ask what the best way is in BaseX to create XPath expressions 
once I identify a certain span in an XML file. More concretely, I usually 
tokenize a text contained in an XML document, and I would like to specify for 
each token its position in the original document. Thanks.


Does https://www.w3.org/TR/xpath-functions/#func-path help?


Re: [basex-talk] losses von tags?

2017-11-01 Thread Martin Honnen

Am 01.11.2017 um 22:54 schrieb michael4...@arcor.de:


Hello,


There is a *problem in transforming data vom XML in HTML*.

In XML there are HTML-tags included.

XML original: *text is important.*

HTML goal: *text is important.*



(1) result: text is important.

let $data := text is important.
return
  {$data/*data()*}


(2) result: text is important.

let $data := text is important.
return
  {$data/*text()*}


(3) result: text is important.

let $data := text is important.
return
  {*$data*}


Is there another possibility to get the result desired?



Use $data/node() to select all child nodes of the "dat" element.




Re: [basex-talk] XML import issue (header related)

2017-09-01 Thread Martin Honnen

On 01.09.2017 22:01, Alexander Holupirek wrote:

On 1. Sep 2017, at 19:41, Ron Katriel  wrote:
Is there a way simpler way around this - other than modifying the input header 
to remove the namespace declaration?



declaring a default element in your XQuery might help?

```xquery
declare default element namespace "http://www.drugbank.ca;;

for $drug in doc('drugbank.Lepirudin.ATC.fail.xml')/drugbank/drug
where not(empty($drug/atc-codes/atc-code))
return  {


But that would also put the result elements into that namespace, not 
sure whether that is wanted.


Re: [basex-talk] XML import issue (header related)

2017-09-01 Thread Martin Honnen

On 01.09.2017 19:41, Ron Katriel wrote:
Thanks Martin. Below is the modified query with the namespace 
specification and usage. It works but is cumbersome.


Is there a way simpler way around this - other than modifying the input 
header to remove the namespace declaration?


I don't think you can avoid the namespace declaration,


declare namespace xs="http://www.drugbank.ca;;

for $drug in db:open('DrugBankFail')/xs:drugbank/xs:drug
where not(empty($drug/xs:atc-codes/xs:atc-code))
return  {
    { string-join(distinct-values($drug/xs:name), ' | ') } ,
    { string-join(distinct-values(for $level in 
$drug/xs:atc-codes/xs:atc-code/xs:level return if 
(fn:string-length($level/@code) = 5) then $level/text() else ()), ' | ') 
} ,


I would shorten lines like the above to e.g.

 { 
string-join(distinct-values($drug/xs:atc-codes/xs:atc-code/xs:level[string-length(@code) 
= 5]), ' | ') } 






Re: [basex-talk] json-to-xml and xpath

2017-08-26 Thread Martin Honnen

On 26.08.2017 12:23, Günter Dunz-Wolff wrote:


I’m trying to get data out of json via xquery.
This is my scenario:
1. Fetching data with fetch:text() calling a REST-API
2. Transforming the data with json-to-xml, so I’ll get something like
http://www.w3.org/2005/xpath-functions“>

gehen
...

...

3. In my xqm-file I have: let $json_xml := json-to-xml(my_fetched_json)
4. I try to get „gehen“ with $json_xml//string[@key='word1‘], but it yields 
nothing, also $json_xml//string yields nothing. Only $json_xml//text() yields 
all string-values into a long string.

What am I doing wrong? Or is there another way, to work with JSON-Data to get 
values of a given key?


The elements are in the namespace http://www.w3.org/2005/xpath-functions 
so either use

  $json_xml//*:string[@key='word1']
or make sure you declare a prefix (e.g. 'fn') for the namespace and use 
that prefix in e.g.

  $json_xml//fn:string[@key='word1']



Re: [basex-talk] bug in XPath evaluation

2017-08-20 Thread Martin Honnen

On 20.08.2017 15:29, nikos dimitrakas wrote:


I discovered a strange behavior i BaseX (8.6.5):



But when I evaluate
//S/@k/parent::*[.//@m="V"]
or
//S/@k/..[.//@m="V"]
it does not work. There is no error, just no result.


When I run your path expression directly against your posted sample with


  

  
  
  
  


  
  
  


  


  
  

  
  

  
  
  


  


  

  
  

  
  


  
  

  
//S/@k/..[.//@m="V"]

in the BaseX GUI I get the following result


  
  
  
  


  
  
  


  


  
  


  
  
  


  


  
  


  
  


So how do you run your query when you say you get an empty result?


[basex-talk] Should xml-to-json ignore a "key" attribute of a "map" root element?

2017-08-17 Thread Martin Honnen


When I try

xml-to-json(
  http://www.w3.org/2005/xpath-functions; key="root">
2
a
true
  ,
  map { 'indent' : true() }
)

with BaseX 8.6.5 I get an error "[FOJS0006] Element 'map' must have no 
key.".


Saxon 9.8 however parses that input fine.

Looking at https://www.w3.org/TR/xpath-functions-31/#func-xml-to-json 
there is some text saying "An element node E having a key attribute 
and/or an escaped-key attribute provided that E would satisfy one of the 
above conditions if the key and/or escaped-key attributes were removed." 
which sounds as if a "key" attribute should or could be ignored.


Or is BaseX schema-validating the argument and that way ("Otherwise, the 
processor may attempt to validate the element against the schema, in 
which case it is treated as valid if and only if the outcome of 
validation is valid.") the "key" attribute is not allowed?


It seems the spec that way allows some confusing lack of interoperability.



Re: [basex-talk] BASEX: REST: PUT to change a XML file in DB

2017-07-10 Thread Martin Honnen

On 10.07.2017 15:16, Roland Krause wrote:

Hi all,

I installed basex for keeping and updating XML files.

I can load a XML into a browser with javascript
...
var xhr = new XMLHttpRequest();
xhr.open( "GET", "http://localhost:8984/rest/XMLfiles/cmuInput.xml;, true);
xhr.send();
var xml = xhr.responseXML;
...

but if I try to PUT something, it will not work.
...
var xhr = new XMLHttpRequest();
xhr.open( "PUT", "http://localhost:8984/rest/XMLfiles/test.xml;, true);
xhr.setRequestHeader("Authorization", "Basic " + btoa("admin:admin"));
xhr.send("hat ein Ende, nur die Wurst hat zwei");
​...​

*[HTTP/1.1 400 Bad Request 6ms]*


I have never tried a PUT with client-side Javascript but as far as I 
remember from POST requests if you want to send XML you should pass a 
DOM document to the send method e.g. in your case you can parse the 
string into a document using DOMParser


  xhr.send(new DOMParser().parseFromString('', 'application/xml'));






[basex-talk] Problem with serialize function and use-character-maps option

2017-06-18 Thread Martin Honnen


When I try

serialize("This is a test with a slash / Test.", map { 'method' : 
'json', 'use-character-maps' : map { '/' : '/'}})


with BaseX 8.6.4 is indicates an error [SEPM0017] Invalid 
'use-character-maps' value 'map { "/": "/" }'; must be a string.


However, the W3C spec 
https://www.w3.org/TR/xpath-functions-31/#func-serialize suggests the 
syntax is

  use-character-mapsmap(xs:string, xs:string)?
with "For the use-character-maps option, the value is a map, whose keys 
are the characters to be mapped (as xs:string instances), and whose 
corresponding values are the strings to be substituted for these 
characters.".


So it seems BaseX is not implementing the finalized spec here.


Re: [basex-talk] restxq output cdata-section-elements

2017-06-01 Thread Martin Honnen



Am 01.06.2017 um 23:19 schrieb Maximilian Gärber:

Hi,

when setting

   %output:cdata-section-elements("KSP DESCRIPTION")

on a restxq request, I get


Zur Aktivierung des...
  außerordentlich hoher Biotingehalt (3
Millionen µg pro kg)
  gut bioverfügbares Zinksulfat
  ausgewogenes Biotin-Zink-Verhältnis
   


I would expect everything inside the DESCRIPTION element to be part of
CDATA. But CDATA ends before the first child element



You would need to make sure the element contains text content, for 
instance by serializing the child elements first with the XPath/XQuery 
3.0 serialize function.


[basex-talk] Calling the sort function with two arguments

2017-03-22 Thread Martin Honnen


According to https://www.w3.org/TR/xpath-functions-31/#func-sort the 
sort function allows one or two or three arguments, however when doing


sort((5, 3, 4, 1), default-collation())

in BaseX 8.6.2 I get an error

java.lang.ArrayIndexOutOfBoundsException: 2
at org.basex.query.func.fn.FnSort.iter(FnSort.java:34)
at org.basex.query.QueryContext.iter(QueryContext.java:394)
at org.basex.query.scope.MainModule.iter(MainModule.java:117)
at org.basex.query.QueryContext.iter(QueryContext.java:330)
at org.basex.query.QueryContext.cache(QueryContext.java:609)
at org.basex.query.QueryProcessor.cache(QueryProcessor.java:113)
at org.basex.core.cmd.AQuery.query(AQuery.java:86)
at org.basex.core.cmd.XQuery.run(XQuery.java:22)
at org.basex.core.Command.run(Command.java:257)
at org.basex.core.Command.execute(Command.java:93)
at org.basex.gui.GUI.exec(GUI.java:471)
at org.basex.gui.GUI.access$300(GUI.java:44)
at org.basex.gui.GUI$6.run(GUI.java:413)


A similar error occurs with

sort((5, 3, 4, 1), ())

Is BaseX 8.6.2 not yet in line with the freshly published spec?

Regards,

Martin Honnen