Re: [basex-talk] BaseX installation cannot see Java

2024-05-07 Thread Martin Honnen



On 07/05/2024 17:15, ykhab...@bellsouth.net wrote:

Hello,

Trying to install BaseX via launching BaseX110-20240320.152714.exe in
Windows 10 OS environment in a corporate environment.
The build version is irrelevant. I tried few of them with the same outcome.
Even running the installation as "Run as administrator".
Also, I am a local admin on the PC.

Unfortunately, I am getting the following error message dialog box:

---
BaseX Setup
---
Please install Java 11 or higher before executing the installer.
---
OK
---

Somehow the BaseX setup cannot find Java on the machine.
Though the OpenJDK Runtime Environment Temurin-17.0.8.1+1 (build 17.0.8.1+1)
is installed.
The current BaseX installation is working properly.

1) Executing this XQuery in BaseX GUI to get Java VM properties:
for $p in proc:property-names()[starts-with(., 'java.vm.')]
return $p || ': ' || proc:property($p)

It emits the following:

java.vm.compressedOopsMode: 32-bit
java.vm.info: mixed mode, sharing
java.vm.name: OpenJDK 64-Bit Server VM
java.vm.specification.name: Java Virtual Machine Specification
java.vm.specification.vendor: Oracle Corporation
java.vm.specification.version: 17
java.vm.vendor: Eclipse Adoptium
java.vm.version: 17.0.8.1+1

2) Issuing PATH statement at the command prompt shows the following:
PATH=C:\Program Files\Eclipse
Adoptium\jre-17.0.8.101-hotspot\bin;C:\WINDOWS\system32;...


If you use

  java -version

at the command prompt, does it give 17?



Re: [basex-talk] Request and JSON parsing

2024-04-25 Thread Martin Honnen


On 25/04/2024 21:58, Günter Dunz-Wolff wrote:

Hi there,

via RESTXQ I request a vectorstore. The response is an JSON-Object.

For example:
With the following curl:

curl https://vector.io/query-data \

  -H "Authorization: Bearer ABcFMGhetc" \

  -d '{ "data": "Du hast dem Menschen ein so freies, herrliches und
üppiges Leben bestimmt", "topK": 2, "includeVectors": false,
"includeMetadata": true }'


I'm getting this object:


{

"result" : [ {

    "id" : "ba02277",

"score" : 0.9949091,

"metadata" :
{"genre":"ba","blatt":"1810-01","autor":"Kleist","titel":"Zoroaster.","link":"https://kleist-digital.de/etc","text":"freies,
herrliches und üppiges Leben bestimmt."}

  }, {

    "id" : "ba01711",

"score" : 0.8891792,

"metadata" :
{"genre":"ba","blatt":"1810-29","autor":"Ompteda","titel":"Fragmente","link":"https://kleist-digital.de/etc","text":"So
mit dem Menschen im Moralischen."}

  } ]

}









Score:  result score

Blatt:  result blatt

Autor:  result autor

Titel:  result titel

Text:  result text

Link:  result link











etc.






Parse the result (if it is not parsed and you have it as  JSON string)
with parse-json($result)) then run XQuery like



{
parse-json($result)?result?*!(let $score := ?score return ?metadata ! 

    Score:  {$score}

    Blatt:  {?blatt}

    Autor:  {?autor}

    Titel:  {?titel}

    Text:  {?text}

    Link:  {?link}


)
}



and it should give you something like



  
    
  Score: 
  0.9949091
    
    
  Blatt: 
  1810-01
    
    
  Autor: 
  Kleist
    
    
  Titel: 
  Zoroaster.
    
    
  Text: 
  freies, herrliches und üppiges Leben bestimmt.
    
    
  Link: 
  https://kleist-digital.de/etc
    
  
  
    
  Score: 
  0.8891792
    
    
  Blatt: 
  1810-29
    
    
  Autor: 
  Ompteda
    
    
  Titel: 
  Fragmente
    
    
  Text: 
  So mit dem Menschen im Moralischen.
    
    
  Link: 
  https://kleist-digital.de/etc
    
  



It is not quite the result you showed but I have left out the outer `li`
elements as an li inside a div doesn't make sense


Fiddle
https://bxfiddle.cloud.basexgmbh.de/?share=%28%27query%21%27%3Cdiv%3EH%28H%3Fresult%3F*%27%3A%7Blet+%24V+%3A%3D+%3FV+return+%3Fmetadata+%27_%3CulUScore5%24V3BlattYblatt3AutorYautor3TiwlYtiwl3TextYwxt3LinkYlink%29IJIli%3EHHIul%3EH%7DH%29HIdiv%3E%27%7Econwxt%21%27%28C6resultG%5BW2277z9949091%2CCE-01NautorRKleistNtiwlRZoroaswr.ND6freies%2C+herrliches+und+%C3%BCppiges+Leben+bestimmt.6%29C%29%2CW1711z8891792%2CCE-29NautorROmpwdaNtiwlRFragmenwND6So+mit+dem+Menschen+im+Moralischen.6%29C%29+%5DHH%29%27%7Emode%21%27XQuery+%7BBaseX%7D%27%7EconwxtType%21%27json%27%293%29IJIliU5_IJ+%3CJ%286%5C%27CHHPDlinkRhttps%3A%2F%2Fkleist-digital.de%2FetcNwxt%5C%21EP6metadataG%286genreRbaNblattR1810G6+_H%5CnI%3C%2FJspan%3EN6%2C6P++R%5C%216U%3EHH%5Ct%3Cli%3E%3CJVscoreW+%28CP6idG6ba0Y5%3F_%3A+wtez6%2CCP6VG0.%01zw_YWVURPNJIHGEDC653_


Re: [basex-talk] Performance issue with BaseX CLI

2024-04-19 Thread Martin Honnen


Am 19.04.2024 um 10:45 schrieb ANDRADE Antonio:


Hie,

For the purposes of European Water Framework Directive reporting, I
compared the performances of the Saxon and BaseX XQuery engines. I
observe a performance gap of a factor of 100 to 200 depending on the
use case (see functions test_xquery_monitoring() and
test_xquery_multischema_2022() in scripts test_saxoncee.py and
test_basex.sh available at
https://outil-transferts.ofb.fr/?107ae461a144d0b) Can you please help
me understand the reasons for such gaps ?


I haven't tried to look at your files either but would also say that
SaxonC from Python is usually faster than Saxon Java when run from a
shell script so some difference you might see is just the advantage of
the AOT compiled SaxonC over running a classic Java app from a shell
script where JVM start up/warm up is making a single run of code seem
always relatively slow.


Re: [basex-talk] some eq versus =

2024-04-08 Thread Martin Honnen


On 08/04/2024 23:58, Leo Studer wrote:

Hello

are the following queries equivalent?

1. //*city*[*some* *$city* *in* following::*city* *satisfies*
/string/(.) eq /string/(*$city*)]


2. //*city*[.=following::*city*]




More or less, I would say, depending on whether there is schema-aware
processing done or not where perhaps . = following::city might not do
string comparison.


Re: [basex-talk] Item Separator

2024-02-27 Thread Martin Honnen

Just to be clear:


Is item-separator set as the empty string or is it not set at all for
the cases where you don't get the result you expect?

My tests with (the lastest) Saxon HE 12.4:

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

declare option output:method 'text';

let $xml:=text1text2
return $xml/element/text()


gives

text1text2


while


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

declare option output:method 'text';

let $xml:=text1text2
return $xml/element/string()


gives

text1 text2


On the other hand


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

declare option output:method 'text';

declare option output:item-separator '';


let $xml:=text1text2
return $xml/element/text()


gives


text1text2


as does


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

declare option output:method 'text';

declare option output:item-separator '';


let $xml:=text1text2
return $xml/element/string()


I see that as correct reading
https://www.w3.org/TR/xslt-xquery-serialization-31/#serdm, in particular
points 3, 4, 5, 6 of the steps in computing a normalized sequence.

On 27/02/2024 22:01, Leo Studer wrote:

Thanks Hans-Jürgen

Indeed, with BaseX I get the same output for text nodes and strings.
This is also how I understand the serialisation definition. Eventually
Saxonica has another take on this???

Warmest,
Leo





On 27 Feb 2024, at 12:16, Hans-Juergen Rennau  wrote:

Dear Leo,

it is important to remember that /serialization/ - the transformation
of the logical query result, which is an XDM value, into a sequence
of octets - is defined by a W3C spec [1], and this definition is
extremely detailed and precise.

The item separator parameter is applied when concatenating strings.
It is not applied when concatenating text nodes, the contents of
which are concatenated without any separator. In one case of your
example the logical query result is a sequence of text nodes, in the
other case it is a sequence of strings. By the way, extreme standard
conformance is a hallmark of BaseX.

Kind regards,
Hans-Jürgen

[1] https://www.w3.org/TR/xslt-xquery-serialization-31/

Am Dienstag, 27. Februar 2024 um 12:03:55 MEZ hat Leo Studer
 Folgendes geschrieben:


Hello

I am serialising the following expressions on oxygen/saxonEE12.3 as
text (item-separator=“”) and wonder why the differente outputs

*let**$xml*:=text1text2*return**$xml*/*element*//text/()

gives
text1text2

And

*let**$xml*:=text1text2*return**$xml*/*element*//string/()

text1 text2


When I set the item-separator =“, “ then I get

text1, text2

Or

text1, , text2


Any explanations???

Thanks,
Leo




Re: [basex-talk] Help with usage of Regex while deleting resources

2024-02-12 Thread Martin Honnen


On 12/02/2024 18:03, Deepak Dinakara wrote:



Similarly I also want to execute queries against a list of collections
using regex.
Something like "*for $document in collection('db-name/20230*')*"
(First 9 months of 2023)
Right now, I am doing something like
"for $i in ('01', '02', '03', '04', ... '09')
for $document in collection('test-collection/2023' || $i)"
But if there are better ways, kindly let me know.


That one could at least use "to" e.g.

  for $i in (1 to 9)!format-integer(., '01')

Not sure that is an improvement, decide for yourself.


Re: [basex-talk] Processing stack traces in XQuery code

2024-01-11 Thread Martin Honnen


> Am 11.01.2024 um 12:37 schrieb Omar Siam :
> 
> I get: Unknown function: fn:stack-trace() when I use stack-trace().
> 
> 
Ah, sorry, it looks like it is not yet implemented. Wait for Christian to give 
you hopefully some better info than my ill guess.



Re: [basex-talk] Processing stack traces in XQuery code

2024-01-11 Thread Martin Honnen


> Am 11.01.2024 um 12:15 schrieb Omar Siam :
> 
> Hi,
> 
> Until 10.6 one could find the stack trace of an error in $err:additional. 
> This feature is now gone from BaseX and the documentation.
> 
> I made my life much easier with reporting stack traces on errors in RestXQ 
> endpoints. Now I don't see how to get that information anymore.
> 
> Any advice how to get this functionality back?

It might be that 
https://qt4cg.org/specifications/xpath-functions-40/Overview.html#func-stack-trace
 is already supported (but I haven´t checked).



[basex-talk] fiddle certificate error

2024-01-09 Thread Martin Honnen



Hi,

trying to access https://bxfiddle.cloud.basexgmbh.de/ Chrome tells me

Your connection is not private
Attackers might be trying to steal your information from
bxfiddle.cloud.basexgmbh.de (for example, passwords, messages, or credit
cards). Learn more
NET::ERR_CERT_DATE_INVALID

bxfiddle.cloud.basexgmbh.de normally uses encryption to protect your
information. When Chrome tried to connect to bxfiddle.cloud.basexgmbh.de
this time, the website sent back unusual and incorrect credentials. This
may happen when an attacker is trying to pretend to be
bxfiddle.cloud.basexgmbh.de, or a Wi-Fi sign-in screen has interrupted
the connection. Your information is still secure because Chrome stopped
the connection before any data was exchanged.

You cannot visit bxfiddle.cloud.basexgmbh.de right now because the
website uses HSTS. Network errors and attacks are usually temporary, so
this page will probably work later.


It seems the certificate expired on Jan 2nd of this (new) year.

Anyone can fix this?





Re: [basex-talk] XQuery fold-left Problem

2023-12-19 Thread Martin Honnen


On 19/12/2023 09:53, Marco Duiker - LandGoed wrote:

Please help me with the following problem:

I try to construct the current status of a series of objects along the
following simple rules:

  *  the current status of on object with a certain `identificatie`
(id) is the newest version of that object
  * except when the newest object has the property
`beëindigen` then the object stops existing.

I use a fold-left to proces these rules with a simple function
implementing those rules. This gives me unexpected results.

I've reduced the problem to a single stand alone query in which the
last object (`obj3`) has the property `beëindigen`.

So I would expect this line:
`let $stand4 := fold-left(($obj3, $obj2, $obj1), (), function($stand,
$obj) { local:stand-totaal($stand, $obj) })`
to give me an empty result as `obj3`has the property
beëindigen
but I am getting `obj1` as demonstrated in the following stand alone
query.

When running the stand alone query I would *expect*:


    declare function local:stand-totaal
  (: returns an object by comparing new to old :)
  (: newest should be returned, except when
 beëindigen
 then no object should be returned :)
  ($new as item()*,
   $old as item()*) as item()* {

   let $new_ids := local:id($new)
   let $stand_deel1 :=
 for $obj_oud in $old//*:owObject
   where not(local:id($obj_oud) = $new_ids)
 return { $obj_oud }
   let $stand_deel2 :=
 for $obj_new in $new//*:owObject[not(.//*:status)]
    return { $obj_new }

   return ($stand_deel1, $stand_deel2)
    };


From your comment and explanation I kind of would expect a check for
that particular value

     beëindigen

but that value is not checked for or mentioned at all in the XQuery code.




Re: [basex-talk] XQuery fold-left Problem

2023-12-19 Thread Martin Honnen


On 19/12/2023 09:53, Marco Duiker - LandGoed wrote:

Please help me with the following problem:

I try to construct the current status of a series of objects along the
following simple rules:

  *  the current status of on object with a certain `identificatie`
(id) is the newest version of that object
  * except when the newest object has the property
`beëindigen` then the object stops existing.

I use a fold-left to proces these rules with a simple function
implementing those rules. This gives me unexpected results.

I've reduced the problem to a single stand alone query in which the
last object (`obj3`) has the property `beëindigen`.

So I would expect this line:
`let $stand4 := fold-left(($obj3, $obj2, $obj1), (), function($stand,
$obj) { local:stand-totaal($stand, $obj) })`
to give me an empty result as `obj3`has the property
beëindigen
but I am getting `obj1` as demonstrated in the following stand alone
query.



At least another XQuery 3.1 processor that BaseX (tried with SaxonC HE
12.4) also outputs


3 - 2 - 1 
http://www.geostandaarden.nl/bestanden-ow/standlevering-generiek;>
   http://www.geostandaarden.nl/imow/bestanden/deelbestand;
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance;>
  http://www.geostandaarden.nl/imow/regels;>
nl.imow-mnre1034.juridischeregel.OR27
http://standaarden.omgevingswet.overheid.nl/idealisatie/id/concept/Exact
 
    http://www.w3.org/1999/xlink;
xlink:href="nl.imow-mnre1034.regeltekst.OR27"/>
 
http://standaarden.omgevingswet.overheid.nl/thema/id/concept/WaterEnWatersystemen
 
    http://www.geostandaarden.nl/imow/locatie;
xmlns:xlink="http://www.w3.org/1999/xlink;
xlink:href="nl.imow-mnre1034.ambtsgebied.LND6030B"/>
 
  
   



so it looks, if that is not the result you want, as if the problem is
likely in your code.



Re: [basex-talk] Passing an array to REST HTTP service

2023-11-03 Thread Martin Honnen


On 03/11/2023 08:30, Csaba Fekete wrote:


I defined an array variable in my XQUERY:

declare variable $caas array(xs:integer)external := [];

How can I assign a value (e.g [1,2]) to this variable through the URL?
I have already tried:
http://host:port/rest/dbname?run=query.xq&$ca[]=1&$ca[]=2
That didn't work. Neither did this:
http://host:port/rest/dbname?run=query.xq&$ca=1,2


Perhaps

  $ca=[1,2]

? Not sure whether square brackets in a URL query part need some
escaping, however.


Re: [basex-talk] Strange "group by" behavior

2023-10-06 Thread Martin Honnen


On 06/10/2023 09:16, Alexander Krasnogolowy wrote:

Given the following XQuery:
let $input := 
a1
b2
b3
              

let $map :=  map:merge((
  map:entry(1, "A"),
  map:entry(2, "B"),
  map:entry(3, "C")
))

for $result in $input/*
let $key := $result/key/text()
let $value := $result/value/text()
group by $key
return map:get($map, $key)

When trying to execute that query, I get the error "Item expected,
sequence found: (map {1:"A",2:"B",3:"C"}, map {1:"A",2:"B",3:"C"}).
But why does it group the map? It isn't part of that for-loop but
rather some kind of global variable. Or do I misunderstand the "group
by" clause?
I only expect the $value to be grouped which results in a sequence.



Use


let $input := 
a1
b2
b3
  ,

$map :=  map:merge((
  map:entry(1, "A"),
  map:entry(2, "B"),
  map:entry(3, "C")
))
return
for $result in $input/*


to ensure the `group by` clause doesn't change the variable bindings for
$input and $map. I am not sure the rest of the code makes sense but you
might know better what you want to achieve.


Re: [basex-talk] passing complex parameters to modules

2023-08-13 Thread Martin Honnen


On 13.08.2023 04:15, Graydon Saunders wrote:

Hello --

I've got a module full of functions.  I've got two (and expect more)
queries which import the function module.  The queries have slightly
different requirements; for example, in one case, it's necessary to
use normalize-unicode() during a data regularization step, and in the
other case it isn't.  These differences are generally not at the top
level of function that the query itself calls; they're usually a
couple levels down in the function module.

It doesn't look like the function module can have its own external
variables; if it can, that'd be ideal.


A libary module can certainly have external variables:

PS C:\Users\marti\OneDrive\Documents\XQuery\module-var-test> type
.\module1.xqm
module namespace module1 = "http://example.com/module1;;

declare variable $module1:var1 as xs:string external;

declare function module1:foo() {
  $module1:var1
};
PS C:\Users\marti\OneDrive\Documents\XQuery\module-var-test> type
.\main-module1.xq
import module namespace module1 = "http://example.com/module1; at
"module1.xqm";

module1:foo()
PS C:\Users\marti\OneDrive\Documents\XQuery\module-var-test> &
'C:\Program Files (x86)\BaseX\bin\basex.bat'
'-b{http://example.com/module1}var1=test' .\main-module1.xq
test




Re: [basex-talk] Counterintuitive behavior with cast to double

2023-05-23 Thread Martin Honnen



On 5/23/2023 11:35 AM, Shuxin Li wrote:

Hi,

I'm Shuxin. Recently I came across this test case in which BaseX
returned counterintuitive result. From my feelings it seems like a bug
but the behavior of Saxon is similar, and therefore is hard for me to
confirm.
Give XML document

111

and XPath query

//*[boolean(.) cast as xs:double]

Both Saxon and BaseX return the result node set [1, 2]. However, the
nodes with id 2 and 3 seems identical to me and is hard to understand
why node 2 is selected while 3 is not. If node 2 is deleted from the
XML document, result set [1,3] is returned. I'm interested in whether
this is intended behavior which I might have limited knowledge of? If
it is also of interest for you you may have a look. Thank you very much!


boolean(.) in a predicate of a node will always be true, so what you
have is

   //*[true() cast as xs:double]

which is

  //*[1]

which is

  /descendant-or-self::node()/*[1]

and that holds for the outer P element being the first child of the
document node and for the A1 id="2" element being the first child of the
P element.

If you remove the first A1, then the previously second child is now the
first child *[1] of the P and therefore selected as well.


So in my view the result of Saxon and BaseX is fine.



Re: [basex-talk] "class file versions" discrepancy

2023-03-14 Thread Martin Honnen


Am 3/14/2023 um 3:18 PM schrieb Martin Honnen:



Am 3/14/2023 um 3:10 PM schrieb Murray, Gregory:



I’m new to BaseX. I’m on a Mac with an Apple M1 chip, running macOS
12.6.3. I downloaded the ZIP distribution of BaseX. When I open
BaseX.jar I get an error message saying to check the console. When I
run basexgui at the command line, I get this error:

Exception in thread "main" java.lang.UnsupportedClassVersionError:
org/basex/BaseXGUI has been compiled by a more recent version of the
Java Runtime (class file version 55.0), this version of the Java
Runtime only recognizes class file versions up to 52.0

I updated Java to the latest version, according to the download page
at java.com and according to the Update tab in the Java control panel
in System Preferences. Running java -version returns this:

java version "1.8.0_361"

Java(TM) SE Runtime Environment (build 1.8.0_361-b09)

Java HotSpot(TM) 64-Bit Server VM (build 25.361-b09, mixed mode)

However, I am still getting the same error when running basexgui. Is
there a trick or workaround for this?



You need Java 11 for BaseX 10, I think. I would think it should be
somehow available on maxOS 12 but I don't do much on a Mac.



https://adoptium.net/temurin/releases/?version=11 has a macOS aarch64
version.


Re: [basex-talk] "class file versions" discrepancy

2023-03-14 Thread Martin Honnen


Am 3/14/2023 um 3:10 PM schrieb Murray, Gregory:



I’m new to BaseX. I’m on a Mac with an Apple M1 chip, running macOS
12.6.3. I downloaded the ZIP distribution of BaseX. When I open
BaseX.jar I get an error message saying to check the console. When I
run basexgui at the command line, I get this error:

Exception in thread "main" java.lang.UnsupportedClassVersionError:
org/basex/BaseXGUI has been compiled by a more recent version of the
Java Runtime (class file version 55.0), this version of the Java
Runtime only recognizes class file versions up to 52.0

I updated Java to the latest version, according to the download page
at java.com and according to the Update tab in the Java control panel
in System Preferences. Running java -version returns this:

java version "1.8.0_361"

Java(TM) SE Runtime Environment (build 1.8.0_361-b09)

Java HotSpot(TM) 64-Bit Server VM (build 25.361-b09, mixed mode)

However, I am still getting the same error when running basexgui. Is
there a trick or workaround for this?



You need Java 11 for BaseX 10, I think. I would think it should be
somehow available on maxOS 12 but I don't do much on a Mac.

If you really need to use Java 8 (1.8) then you can try the latest BaseX
9 release, I guess.




Re: [basex-talk] XQuery Prolog with serialization settings - basex "Unknown option 'basex'?

2023-02-13 Thread Martin Honnen



On 2/13/2023 8:28 PM, Patrick Durusau wrote:

Greetings!

I have the following in the prolog of an XQuery:

declare namespace output =
'http://www.w3.org/2010/xslt-xquery-serialization';
declare option output:method 'basex';
declare option output:basex 'indent=yes, newline=\n';

I'm following the example at:
https://docs.basex.org/wiki/Serialization for CSV, reasoning the same
form should work for basex.

Sadly, BaseX 10.4 on Debian reports:

[XQST0109] Unknown option 'basex

Is it because basex isn't in the namespace of
'http://www.w3.org/2010/xslt-xquery-serialization'; ?

OK so I change the namespace to http://tm.durusau.net and it runs!

Sadly not applying the requested formatting.

Some guidance on serialization please?



I think the right syntax is


declare namespace output =
'http://www.w3.org/2010/xslt-xquery-serialization';
declare option output:method 'basex';
declare option output:indent 'yes';
declare option output:newline '\n';



Re: [basex-talk] Minor issue: format-date?

2023-01-20 Thread Martin Honnen



Am 1/20/2023 um 11:44 AM schrieb Alexander Witzigmann:

Hi,

The format-date has one minor issue using

format-date(xs:date("2022-01-01"),"[D]. [Mn] [Y]","de",(),())

should return
1. Januar 2022
but currently (BaseX 10.4) returns
1. januar 2022



I think you need/want to use

   format-date(xs:date("2022-01-01"),"[D]. [MNn] [Y]","de",(),())

Your sample gives the same output for me with BaseX and Saxon.



Re: [basex-talk] Scope of a xPath variable

2022-12-19 Thread Martin Honnen



On 12/19/2022 10:58 PM, Graydon wrote:

On Mon, Dec 19, 2022 at 10:43:25PM +0100, Leo Studer scripsit:

In the code below I encounter the problem, that I have to define the same xPath 
function variable $organizations twice and I do not understand why.

In line 10, you've used a let clause to bind a variable of type function to the 
name organizations.  That's in context a specific FLOWR expression.

The expression in the return clause of that FLOWR expression returns an
element constructor where the contents expression contains another FLOWR
expression.  The first definition on line 10 will be out of scope in
there.


I don't think so, the variable is not out of scope, it is bound for each
item in the group to that function, meaning that value in the return
clause of the group is a sequence of functions and that way

  head($organizations)($country)

would work.


You could define the function with scope for the module:

declare function local:getOrganizations($in as element(country))
 as xs:string* {
   let $thisCountry as xs:string := $in/@id/string();
   return $doc//organization[members/@country = $thisCountry]/@abbrev/string(.)
};




That is certainly the cleaner way.



Re: [basex-talk] Scope of a xPath variable

2022-12-19 Thread Martin Honnen


On 12/19/2022 10:43 PM, Leo Studer wrote:

Hello Cracks ;-)

In the code below I encounter the problem, that I have to define the
same xPath function variable $organizations twice and I do not
understand why.
Running the code with the newest versions of BaseX or with Saxon EE, I
get a runtime error when I leave the second definition of
$organizations out.

Any explanation? Thanks in advance.

Happy Holidays
Always, Leo



xquery version "3.1" encoding "UTF-8";
declare variable $doc := doc("factbook.xml");

*element**Memberships*{
*let**$membershipPotentcy*:=*function*(*$orgs*){*if*(/count/(*$orgs*)le0)
*then*'none'
*else**if*(/count/(*$orgs*) le5) *then*'few'
*else*'many'}
*let**$organizations*:=*function*(*$country*){*$doc*//*organization*[*members*/*/@country/*=*$country*/*/@id/*]/*/@abbrev/*//string/(.)}
*for**$countries**in**$doc*//*country*
*group by**$mp*:=*$membershipPotentcy*(*$organizations*(*$countries*))
*order by**$mp*
*return*
*element*{*$mp*} {
*for**$country**in**$countries*
*let**$organizations*:=*function*(*$country*){*$doc*//*organization*[*members*/*/@country/*=*$country*/*/@id/*]/*/@abbrev/*//string/(.)}
*order by**$country*/*/@name/*
*return*
{*$country*/*/@name/*,*$organizations*(*$country*)}
}}



Which runtime error do you get? I guess the group by binds your let
variable for each country in the group so perhaps

  head($organizations)($country)

would suffice without redefining the variable.

It would be an odd way to solve it, I would prefer to have a


declare function local:organizations($country)


declared before.


Re: [basex-talk] Pretty print

2022-11-17 Thread Martin Honnen



Am 11/17/2022 um 2:29 PM schrieb Giuseppe G. A. Celano:



it is:

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

doc(“myfile.xml”)




How/where are you running that code? In the BaseX GUI? There I get an
indented output with similar code.



Re: [basex-talk] Pretty print

2022-11-17 Thread Martin Honnen



Am 11/17/2022 um 2:10 PM schrieb Giuseppe G. A. Celano:

Hi,

I am trying to prettyprint an XML file. I tried the serialization option 
“indent”=“yes”, but it does not work as expected. On BaseX 9, the prettyprint 
was the default setting: how to get the same result in BaseX 10 (and later)? 
Thanks.



Can you show us your code?

For me

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

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

declare context item := bar;

.


gives the result


  bar



in 10.3.




Re: [basex-talk] basex client implementation

2022-11-04 Thread Martin Honnen


Am 11/4/2022 um 10:27 AM schrieb Martin Honnen:



Am 11/4/2022 um 1:38 AM schrieb Erik Peterson:

The CLI basexclient uses the same client api as other clients found
here yes? https://docs.basex.org/wiki/Clients

from basexclient CLI
>BINARY GET lib/example.jpg
as expected, returns the jpg I PUT from there from my client app.
However, the same command BINARY GET from my client app, using
COMMAND |{command}| |{result} {info} \00|

 does not return the jpg. The bytes going to the basex server, at
least the command 'BINARY GET lib/example.jpg' part are identical in
both cases.


Which client API exactly do you use, which result or error do you get?

There is a Java sample for a binary resource online at
https://github.com/BaseXdb/basex/blob/10.3/basex-examples/src/main/java/org/basex/examples/api/BinaryExample.java
(confusingly it uses retrieve instead of BINARY GET).


I have tested that the example works with BaseX 103 if "retrieve" is
replaced by "BINARY GET".

So it seems
https://github.com/BaseXdb/basex/blob/10.3/basex-examples/src/main/java/org/basex/examples/api/BaseXClient.java
needs to be updated/patched.


Re: [basex-talk] Lookup operator, conformance

2022-10-24 Thread Martin Honnen


Am 10/24/2022 um 1:29 PM schrieb Martin Honnen:



Am 10/24/2022 um 12:45 PM schrieb Hans-Jürgen Rennau:

Hello,

I noticed that the lookup operator (?) accepts as key expression also
non-parenthesized expressions, e.g.:

$map?$key

It seems to me that the XQuery spec does not allow that - the key
specifier must be an NCName, an integer, * or a parenthesized
expression [1]:
[126] KeySpecifier ::= NCName | IntegerLiteral | ParenthesizedExpr | "*"
So only this should be allowed:
$map?($key)

But I am not quite sure if I do not overlook something.

*My question*: is the acceptance of non-parenthesized key expressions
conformant behaviour, or a (certainly intended) laxness?



If it is BaseX 10 it might be because it already tries to implement
what XQuery 4
https://qt4cg.org/specifications/xquery-40/xquery-40-diff.html#id-unary-lookup
is going to allow:

[141] |KeySpecifier
<https://qt4cg.org/specifications/xquery-40/xquery-40-diff.html#prod-xquery40-KeySpecifier>|
   ::=
|NCName
<https://qt4cg.org/specifications/xquery-40/xquery-40-diff.html#prod-xquery40-NCName>|IntegerLiteral
<https://qt4cg.org/specifications/xquery-40/xquery-40-diff.html#doc-xquery40-IntegerLiteral>|StringLiteral
<https://qt4cg.org/specifications/xquery-40/xquery-40-diff.html#doc-xquery40-StringLiteral>|VarRef
<https://qt4cg.org/specifications/xquery-40/xquery-40-diff.html#doc-xquery40-VarRef>|ParenthesizedExpr
<https://qt4cg.org/specifications/xquery-40/xquery-40-diff.html#doc-xquery40-ParenthesizedExpr>|
"*"|



|In
https://github.com/BaseXdb/basex/commit/cada2554ff3714cdd466a10486d3758855a9203d
I think is the commit to allow a variable.|


Re: [basex-talk] Lookup operator, conformance

2022-10-24 Thread Martin Honnen


Am 10/24/2022 um 12:45 PM schrieb Hans-Jürgen Rennau:

Hello,

I noticed that the lookup operator (?) accepts as key expression also
non-parenthesized expressions, e.g.:

$map?$key

It seems to me that the XQuery spec does not allow that - the key
specifier must be an NCName, an integer, * or a parenthesized
expression [1]:
[126] KeySpecifier ::= NCName | IntegerLiteral | ParenthesizedExpr | "*"
So only this should be allowed:
$map?($key)

But I am not quite sure if I do not overlook something.

*My question*: is the acceptance of non-parenthesized key expressions
conformant behaviour, or a (certainly intended) laxness?



If it is BaseX 10 it might be because it already tries to implement what
XQuery 4
https://qt4cg.org/specifications/xquery-40/xquery-40-diff.html#id-unary-lookup
is going to allow:

[141] |KeySpecifier
|
   ::=
|NCName
|IntegerLiteral
|StringLiteral
|VarRef
|ParenthesizedExpr
|
"*"|


Re: [basex-talk] BaseX 10.2: Maintenance Release

2022-10-11 Thread Martin Honnen



Am 10/11/2022 um 11:59 AM schrieb Christian Grün:

A new maintenance release is available. It comes with…

• a new command-line option -W for indenting results;
• better pooling of HTTP requests;
• minor bug fixes.


Superb, somehow sneaking that in on MS patch day Tuesday but long before
their patches tend to arrive, so now we have got some hours to install
and use the latest BaseX before Windows and MS updates clog our
connections and/or our systems.


Re: [basex-talk] current-dateTime() function precision

2022-09-09 Thread Martin Honnen


On 9/9/2022 7:46 PM, ykhab...@bellsouth.net wrote:


Hi Vincent and Martin,

Thanks for the clarification.

I switched to using the Profiling module.

let $before_datetime := convert:integer-to-dateTime(prof:current-ms())
(: current-dateTime() :)

And it is working well.

2022-09-09T17:31:34.466Z

2022-09-09T17:31:34.538Z

The last remaining task is to convert the output from the UTC time
zone to my local EST:

2022-09-09T13:31:34.466-04:00

Any idea how to achieve that?


There is a function adjust-dateTime-to-timezone, taking a duration, I think.


Re: [basex-talk] current-dateTime() function precision

2022-09-09 Thread Martin Honnen


Am 9/9/2022 um 6:03 PM schrieb Martin Honnen:

I think, due to the functional/declarative language that is XQuery, the
static context defines that current-dateTime() doesn't change during the
execution of a single query, it is part of the static context.



It is defined in the dynamic context:
https://www.w3.org/TR/xquery-31/#eval_context


 *

   [Definition:*Current dateTime.*This information represents
   animplementation-dependent
   <https://www.w3.org/TR/xquery-31/#dt-implementation-dependent>point
   in time during the processing ofa query, and includes an explicit
   timezone. It can be retrieved by the|fn:current-dateTime|function.
   If invoked multiple times during the execution ofa query, this
   function always returns the same result.]


Re: [basex-talk] current-dateTime() function precision

2022-09-09 Thread Martin Honnen



Am 9/9/2022 um 6:03 PM schrieb Martin Honnen:


Am 9/9/2022 um 5:55 PM schrieb ykhab...@bellsouth.net:

Hello,

I am using BaseX v.10.1

It seems that the current-dateTime() function precision is off.

I am validating an XML file against an XSD 1.1 file via Xerces 2.12.2
validator.
And trying to measure a timing of it.

Here is my code.
xquery version "4.0";

let $xml := '\\...\AForm-XSD-20211013\PD220224062681.XML'
let $xsd := '\\...\AForm-XSD-20211013\Miami-ws-AForm.xsd'

let $before_datetime := current-dateTime()
let $result := validate:xsd-report($xml, $xsd, map {
'http://apache.org/xml/features/validation/cta-full-xpath-checking':
true()
})

return 
 {data($result/status)}
 {count($result/message)}
 {$before_datetime}
 {current-dateTime()}
 {$xml}
 {$xsd}
 BaseX {data(db:system()//version)}, EE-Java,
{validate:xsd-processor()} 2.12.2
{validate:xsd-version()}
   
   {$result/message}


It is emitting the following output:

   
 invalid
 3
2022-09-09T11:32:29.667-04:00
2022-09-09T11:32:29.667-04:00
\\...\AForm-XSD-20211013\PD220224062681.XML
\\...\AForm-XSD-20211013\Miami-ws-AForm.xsd
 BaseX 10.1, EE-Java, Xerces 2.12.2
 1.1
   
   
 ...
   


The question is why the before and after timing is the same:
2022-09-09T11:32:29.667-04:00
2022-09-09T11:32:29.667-04:00

They are identical up to a millisecond.



I think, due to the functional/declarative language that is XQuery, the
static context defines that current-dateTime() doesn't change during the
execution of a single query, it is part of the static context.

Most processors have extensions for timestamp and/or profiling, e.g.
Saxon has saxon:timestamp(), I would think that BaseX also has some
extension.


For profiling: https://docs.basex.org/wiki/Profiling_Module


Re: [basex-talk] current-dateTime() function precision

2022-09-09 Thread Martin Honnen



Am 9/9/2022 um 5:55 PM schrieb ykhab...@bellsouth.net:

Hello,

I am using BaseX v.10.1

It seems that the current-dateTime() function precision is off.

I am validating an XML file against an XSD 1.1 file via Xerces 2.12.2
validator.
And trying to measure a timing of it.

Here is my code.
xquery version "4.0";

let $xml := '\\...\AForm-XSD-20211013\PD220224062681.XML'
let $xsd := '\\...\AForm-XSD-20211013\Miami-ws-AForm.xsd'

let $before_datetime := current-dateTime()
let $result := validate:xsd-report($xml, $xsd, map {
'http://apache.org/xml/features/validation/cta-full-xpath-checking': true()
})

return 
 {data($result/status)}
 {count($result/message)}
 {$before_datetime}
 {current-dateTime()}
 {$xml}
 {$xsd}
 BaseX {data(db:system()//version)}, EE-Java,
{validate:xsd-processor()} 2.12.2
 {validate:xsd-version()}
   
   {$result/message}


It is emitting the following output:

   
 invalid
 3
 2022-09-09T11:32:29.667-04:00
 2022-09-09T11:32:29.667-04:00
 \\...\AForm-XSD-20211013\PD220224062681.XML
 \\...\AForm-XSD-20211013\Miami-ws-AForm.xsd
 BaseX 10.1, EE-Java, Xerces 2.12.2
 1.1
   
   
 ...
   


The question is why the before and after timing is the same:
2022-09-09T11:32:29.667-04:00
2022-09-09T11:32:29.667-04:00

They are identical up to a millisecond.



I think, due to the functional/declarative language that is XQuery, the
static context defines that current-dateTime() doesn't change during the
execution of a single query, it is part of the static context.

Most processors have extensions for timestamp and/or profiling, e.g.
Saxon has saxon:timestamp(), I would think that BaseX also has some
extension.



Re: [basex-talk] an Earley parser in XQuery?

2022-08-22 Thread Martin Honnen


On 22.08.2022 19:07, Graydon Saunders wrote:



I'm trying to test if some extracted sentences validate as productions
of a particular context-free grammar expressed in a BNF dialect.

Is there an available implementation of a parser in XQuery that can do
this?


In the context of Invisible XML https://invisiblexml.org/ I have heard
that term "Earley" parser a lot but I am not familiar enough with the
various implementations to tell whether all are "Earley" parsers,
https://github.com/cmsmcq/Aparecium is an XQuery implementation of
Invisible XML.

I think the various NineML tools by Norman Walsh use an Earley parser
and are written in Java, there is an XPath/XQuery/XSLT extension for
Saxon, so it should be possible to integrate that in BaseX, perhaps, too.



Re: [basex-talk] BaseX 10.1: Fixes, Previews

2022-08-18 Thread Martin Honnen



Am 18.08.2022 um 15:09 schrieb Martin Honnen:


Am 18.08.2022 um 12:03 schrieb Christian Grün:

Enjoy the latest BaseX patch release of BaseX, our XML Framework:

   https://basex.org/


…and (still undocumented) XQuery 4 preview features.


Now that sounds interesting, what do we need to do to use them? Start
the code with

xquery version "4.0";

?


That definitely looks the way to go and is pretty interesting:
https://twitter.com/XSLT_knowmad/status/1560256016348057602


Re: [basex-talk] BaseX 10.1: Fixes, Previews

2022-08-18 Thread Martin Honnen



Am 18.08.2022 um 12:03 schrieb Christian Grün:

Enjoy the latest BaseX patch release of BaseX, our XML Framework:

   https://basex.org/

It contains various bug fixes…

• HTTP Requests, sending headers
• Storage handling of main-memory databases
• GUI editor, double clicks
• function items and mixed updates

…and (still undocumented) XQuery 4 preview features.


Now that sounds interesting, what do we need to do to use them? Start
the code with

xquery version "4.0";

?



Re: [basex-talk] Multi-valued values in maps - sequences vs arrays

2022-08-03 Thread Martin Honnen



Am 03.08.2022 um 04:27 schrieb Bridger Dyson-Smith:



I would appreciate some help understanding how I might go about having
a multi-valued array as the value of a map key, or if this is even
possible; e.g.

map{ "key": [1,2,3,4,5] }



map { 'key' : array { 1 to 5 } }


Or have I missed the point?



Re: [basex-talk] BaseX YAML Parser?

2022-07-26 Thread Martin Honnen

Am 26.07.2022 um 15:25 schrieb Marco Lettere:

Hi Elliot,

I remember having asked info about a possible YAML serialization format
on the Slack Xml.com channel one year ago.

They don't really have a nice opinion about Yaml and no-one looked
really interested in supporting it.

Thus I think there are philosophy matters here :-)


I don't remember the details of that request but in general I don't
think some disdain for YAML means you can't support it, I think Calabash
3 for XProc 3 has support for it, as
https://so.nwalsh.com/2020/02/15/xproc-30 says: "The p:load step will
happily load YAML".

Probably no help currently in the context of BaseX and XQuery but at
least some people in the XML community do support reading YAML.



Re: [basex-talk] How To: Sort nodes in document order?

2022-07-04 Thread Martin Honnen


Am 04.07.2022 um 17:14 schrieb Martin Honnen:



Am 04.07.2022 um 17:11 schrieb Eliot Kimber:


I feel like I should know how to do this (and possibly I’ve
previously been told how and have forgotten), but I’m at a loss.

I am implementing a process that gathers nodes from a single document
(a DITA map) and constructs a system of maps where I’m using the maps
primarily to represent a tree and enable lookup of things by key.

However, the order of the elements that make up these maps is also
important (DITA’s rules for how you build DITA key spaces from maps
depends entirely on document order).

For example, I have a map that maps “key names” to the elements that
declare those key names, i.e.:

map { “key-01” : (,
) }

This is the initial state of the map (reflecting pass 1 over the DITA
map document) but then I need to add additional elements to the
sequence that is the value of entry “key-01” and I need the resulting
sequence to be in document order.

So my question: given two sequences of nodes from the same document,
how does one construct a new sequence where the nodes are in document
order?



$seq1 | $seq2 should do, if you want duplicates eliminated.



Otherwise perhaps


sort(($seq1, $seq2), (), function($n) { index-of(($seq1 |
$seq2)!generate-id(), generate-id($n))})




Re: [basex-talk] How To: Sort nodes in document order?

2022-07-04 Thread Martin Honnen


Am 04.07.2022 um 17:11 schrieb Eliot Kimber:


I feel like I should know how to do this (and possibly I’ve previously
been told how and have forgotten), but I’m at a loss.

I am implementing a process that gathers nodes from a single document
(a DITA map) and constructs a system of maps where I’m using the maps
primarily to represent a tree and enable lookup of things by key.

However, the order of the elements that make up these maps is also
important (DITA’s rules for how you build DITA key spaces from maps
depends entirely on document order).

For example, I have a map that maps “key names” to the elements that
declare those key names, i.e.:

map { “key-01” : (, ) }

This is the initial state of the map (reflecting pass 1 over the DITA
map document) but then I need to add additional elements to the
sequence that is the value of entry “key-01” and I need the resulting
sequence to be in document order.

So my question: given two sequences of nodes from the same document,
how does one construct a new sequence where the nodes are in document
order?



$seq1 | $seq2 should do, if you want duplicates eliminated.


Re: [basex-talk] the implicit context of position

2022-06-30 Thread Martin Honnen


Am 30.06.2022 um 17:21 schrieb Graydon Saunders:

Hello --

I've got an element node that's part of a document.  I need its
position among the element children of its parent.

$step/position() will (correctly!) always return 1, there's one thing
in $step, of course it does.

replace($step/path(),'^.*\[(\p{Nd}+)\]$','$1') => xs:integer()

gets me the implicit position but is something of a horror.

for $e at $in in $step/../* where $e is $step return $in

works, too, but any notion of elegance and clarity have fled screaming
into the night.

I keep thinking there must be a better way; anyone got any suggestions?



I think functx has some node-index-of you could use or use e.g.

  index-of($step/../*/generate-id(), generate-id($step))


Re: [basex-talk] Constructing and querying map structures in a dynamic way

2022-05-25 Thread Martin Honnen



Am 25.05.2022 um 17:35 schrieb Markus Elfring:


The standard specification just shows examples for topics like “days”
and “books” with map constructors based on literal data.



Perhaps https://www.w3.org/TR/xquery-31-requirements/ shows some more
complex queries.



Re: [basex-talk] ODBC support for BaseX?

2022-05-20 Thread Martin Honnen



Am 20.05.2022 um 10:56 schrieb Markus Elfring:

The software “BaseX” is providing direct support for document databases.

Is any support available for data management by interfaces like the following?

* Open Database Connectivity
* Java Database Connectivity



Are you just looking for https://docs.basex.org/wiki/SQL_Module?



Re: [basex-talk] Repeating data based on varying items in an array

2022-05-16 Thread Martin Honnen



Am 16.05.2022 um 10:18 schrieb Markus Elfring:

Can you show us the input structure? A sequence of arrays with a string
literal as the first array item but an element or document node as the
second array item?

I stumbled on the design challenge if the sequence of nested arrays would be
constructed by another FLWOR expression (instead of the mentioned test data 
literal).



To me that kind of array with a string literal followed by a an array of
integers seemed kind of an odd data structure to start with so I would
think about just adapting the original FLOWR expression to perhaps
directly output XML or a sequences of maps from string to an array of
integers.

But I don't see any difference in XQuery in general or for that sample
you had, it doesn't really matter whether you have a literal or
construct the data from another FLOWR expression.

Did you run into any problems/errors using the data from a FLOWR
expression? If you need help with that perhaps show a sample and the
error you got.



Re: [basex-talk] Repeating data based on varying items in an array

2022-05-13 Thread Martin Honnen



Am 13.05.2022 um 15:08 schrieb Markus Elfring:


Can such an XQuery script variant be adapted also for the handling of items
from a subtree instead of the shown number array?



Can you show us the input structure? A sequence of arrays with a string
literal as the first array item but an element or document node as the
second array item?

I don't see any problem using e.g.


$values := ?2//foo/data() return $values !

instead of

$values := ?2?* return $values !



Re: [basex-talk] Repeating data based on varying items in an array

2022-05-13 Thread Martin Honnen



Am 13.05.2022 um 13:47 schrieb Markus Elfring:


How do you think about to extend an XQuery sccript variant like the following
for the desired transformation?

declare option output:method "csv";
declare option output:csv "header=yes";
for $x in (["f", [1, 2, 3]], ["g", [4, 5]])
return


{$x(1)}
{$x(2)}




Test result:
key,values
f,1 2 3
g,4 5




Your result asked for in the original question, if it also was meant to
indicate some CSV representation, could be achieved using


declare option output:method "csv";
declare option output:csv "header=yes";


{
(["f", [1, 2, 3]], ["g", [4, 5]]) !
(let $key := ?1, $values := ?2?* return $values!

{$key}
{.}

)
}




Re: [basex-talk] Repeating data based on varying items in an array

2022-05-13 Thread Martin Honnen



Am 13.05.2022 um 12:46 schrieb Markus Elfring:



A sequence like “(["f" [1 2 3]], ["g" [4, 5]])” might be an interesting test 
example.
It contains two nested arrays.



That is not even syntactically close to a sequence of two nested arrays,
I am afraid.




Re: [basex-talk] Performing extra data conversion for double values (by XQuery)

2022-04-21 Thread Martin Honnen



On 21.04.2022 09:20, Markus Elfring wrote:


I would like to perform a sanity check for some input data which represent 
numbers
that are using the comma as the decimal separator.
I stumbled on the message “[FORG0001] Cannot convert to xs:double: …”



Depending on the format of the numeric data it might suffice to use e.g.

  . => translate(',$', '.') => xs:decimal()

to remove e.g. a $ symbol/currency symbol, to replace the comma with a
dot and then to convert the numerical string to an xs:decimal value.


Re: [basex-talk] Support for performing queries on query results

2022-04-04 Thread Martin Honnen



Am 04.04.2022 um 16:16 schrieb Markus Elfring:

for $x in $results

group by $count := $x(1)

I tried the code variant “for $r in $results let $count := $r(1)” also out.
But I wonder that the incidence “1” (only one) would be determined then
for all record set counters.



As I said, consider to provide an input/output sample of what you have
and want to achieve, don't make us guess from your failing queries what
input data you have and which result you want.

A further guess would be that perhaps

  for $x in $results

  group by $count := $x(1)

  let $incidence := count($x)

with the way XQuery binds variables might help as that way the
$incidence what have the values of items in each group established by
the `group by` clause on the `for $x`.



Re: [basex-talk] Support for performing queries on query results

2022-04-04 Thread Martin Honnen



Am 04.04.2022 um 15:27 schrieb Markus Elfring:

for $x in $results
let $count := $x[1]

Perhaps you want

    $x(1)

here to access the first item in the array $x?

Yes. ‒ Thanks that you pointed a typo out.

Thus I adjusted the member access specification.
But I stumble on the message “[XPTY0004] Item expected, sequence found: (1, 1, 
1)”
from the query evaluation.

Which script fine-tuning will help then?


How about showing sample input and output data?

I would guess, that for the grouping you rather want


declare option output:csv "header=yes, separator=|";
let $results :=
for $x in //test_data/product
return array { fn:count($x/contributor), $x/id/data() }

for $x in $results

group by $count := $x(1)



Re: [basex-talk] Support for performing queries on query results

2022-04-04 Thread Martin Honnen



Am 04.04.2022 um 13:00 schrieb Markus Elfring:

With XQuery 3.0, a group by clause was introduced [1, 2]. I can be
applied to all data structures including arrays (“sequences” are the
most basic data structure in XQuery, though).

I am looking for further hints in this software design area.

The following script got parsed.

declare option output:method "csv";
declare option output:csv "header=yes, separator=|";
let $results :=
 for $x in //test_data/product
 return array { fn:count($x/contributor), $x/id/data() }

for $x in $results
let $count := $x[1]


Perhaps you want

  $x(1)

here to access the first item in the array $x?



let $incidence := fn:count($count)
group by $count
order by $incidence descending
return


{$count}
{$incidence}




But I stumble on the message “[XPTY0004] Item expected, sequence found: (1, 
"123").”
from the query evaluation.
https://docs.basex.org/wiki/XQuery_Errors#Type_Errors


Do you find the presented data processing approach reasonable (in principle)?

Regards,
Markus


Re: [basex-talk] Anticipating more complex data to follow

2022-03-22 Thread Martin Honnen



On 22.03.2022 21:48, Patrick Durusau wrote:

I'm anticipating incorporation of JSON sources with anonymous nodes
and if they all appear with the element name _, how do I distinguish
one from another, structurally speaking?



Are you not able to use XPath/XQuery 3.1 map/array lookup operators
directly on your JSON e.g.

  ?parties[exists(?*[?name = 'name1' and ?role = 'CN'])]






Re: [basex-talk] XQuery versus XSL

2022-03-09 Thread Martin Honnen


On 09.03.2022 13:11, Ben Engbers wrote:

Hi,

I have a collection of 740 documents with the following structure:


xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance; 
xsi:noNamespaceSchemaLocation="http://technische-documentatie.oep.overheid.nl/schema/op-xsd-2012-1;>

  
    content="https://zoek.officielebekendmakingen.nl/h-tk-20202021-102-2/metadata.xml; 
/>

  
  
    
  
    
  
    Allereerst hebben we het traditionele mondelinge 
vragenuur. 

  
    
  
  
    
  
    Voorzitter. Het was altijd al een eer om hier te 
staan.

  
  
    De vragen die ik ga stellen, gaan over stikstof.
  
  
    We zijn allemaal 100 kilometer per uur gaan rijden, 
maar er is nog geen gram ammoniak uit de veehouderij minder 
uitgestoten.

  
    
  
  
  
    
  
    U heeft helaas maar één vraag, meneer Ephraim, als 
Groep Van Haga.

  
  
    Ik wil de minister bedanken voor haar beantwoording.
  
    
  
    
  


I want to experiment with textmining and for these experiments, it 
would be usefull if for every , all /text() elements 
were concated.The first option is to use XQuery for concatenating.


Another option is to use XSL to transform the original documents to 
the following structure:



xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance; 
xsi:noNamespaceSchemaLocation="http://technische-documentatie.oep.overheid.nl/schema/op-xsd-2012-1;>

  
    content="https://zoek.officielebekendmakingen.nl/h-tk-20202021-102-2/metadata.xml; 
/>

  
  
    
  
    
  Allereerst hebben we het traditionele mondelinge vragenuur.
    
  
  
    
  Voorzitter. Het was altijd al een eer om hier te staan.
  De vragen die ik ga stellen, gaan over stikstof.
  We zijn allemaal 100 kilometer per uur gaan rijden, maar er 
is nog geen gram ammoniak uit de veehouderij minder uitgestoten.

    
  
  
  
    
  U heeft helaas maar één vraag, meneer Ephraim, als Groep Van 
Haga.

  Ik wil de minister bedanken voor haar beantwoording.
    
  
    
  


Question:
What are the pros and cons of both methods?
Is it difficult to do this in XSL (I have only used very simple 
transformations)?





An XSLT transformation is easy, start with the identity transformation 
as the base template, either in XSLT 3 by declaring


   

or by spelling out in XSLT 2 or 1, then add a template




  




to ensure the all elements nodes below spreekbeurt/tekst are stripped 
and only the text nodes are output.




Re: [basex-talk] validate:xsd-info agains more than one schema

2022-03-04 Thread Martin Honnen


On 04.03.2022 10:28, Arantza Etxebarria Pablo wrote:


Dear Community,


We have been trying to validate a file using the function
*validate:xsd-info*($input as item(), $schema as item()?) as
xs:string* against several different schemas and, we don't know how to
send the parameter “schema” with more than one schema for this function.


We have tried to declare the variable *schema *like this :


let $schema:=
"http://inspire.ec.europa.eu/schemas/bu-base/4.0/BuildingsBase.xsd
http://schemas.opengis.net/gml/3.2.1/gml.xsd;



It seems the first schema imports the second so I would think using the
first schema as the $schema parameter should suffice to have the
validator load any imports. Or did you try that and got other errors or
warnings?



But it returns this error message:

XML document 'example.gml': -1:-1: schema_reference.4: Failed to read
schema document
'http://inspire.ec.europa.eu/schemas/bu-base/4.0/BuildingsBase.xsd
http://schemas.opengis.net/gml/3.2.1/gml.xsd' , because 1) could not
find the document; 2) the document could not be read; 3) the root
element of the document is not .

I have tried this function when no schema is given and it takes the
contain of schemaLocation attribute, and in this case, is able to
validate more than one schema. But I need to pass the schemas through
a variable


Could any of you point us in the right direction?


Thanks


--
*Arantza Etxebarria *



Re: [basex-talk] 'Flatten' a collection

2022-02-14 Thread Martin Honnen

On 14.02.2022 15:53, Ben Engbers wrote:

Hi,

I have a collection of 740 XML-documents which I want to flatten. The
files all have the same structure:


   
   spreker_1
   spreker_3



   
   
spreker_2
spreker_1
spreker_4



   
   spreker_2
   spreker_3
   spreker_2
   spreker_1


The following query gives this result:
import module namespace  functx = "http://www.functx.com;;

let $Blogs := collection("Blog")
let $Turns := collection("Blog")

for $Blog in collection("Blog"),
     $Turn in collection("Blog")
     where $Turn//datum/@date = $Blog//datum/@date
     order by $Blog//datum/@date
     count $Count
   let $Id := $Blog/handeling/@id
   let $Datum := $Blog//datum/@date

   let $Speaker := $Turn//spreker/text()

return($Id, $Datum, $Speaker, $Count)

id="h_1"
date="d_1"
spreker_1
spreker_3
1
id="h_2"
date="d_2"
spreker_2
spreker_1
spreker_4
2
id="h_3"
date="d_3"
spreker_2
spreker_3
spreker_2
spreker_1
3

But what I eventually need is this (for clarity shown as a table):

1, id="h_1", date="d_1", 1, spreker_1
1, id="h_1", date="d_1", 2, spreker_3
2, id="h_2", date="d_2", 1, spreker_2
2, id="h_2", date="d_2", 2, spreker_1
2, id="h_2", date="d_2", 3, spreker_4
3, id="h_3", date="d_3", 1, spreker_2
3, id="h_3", date="d_3", 2, spreker_3
3, id="h_3", date="d_3", 3, spreker_2
3, id="h_3", date="d_3", 4, spreker_1



It seem you want to process each document to generate that first number
(e.g. 1, 2, 3) and then "inside" your want to process each "spreker"
element.

Your shown example data doesn't seem to suggest you need to use any
joins on the two collections as you seem to process the same
collection("Blog") anyway so why does

  for $Blog in collection("Blog")
order by $Blog//datum/@date
  let $Id := $Blog/handeling/@id
  let $Datum := $Blog//datum/@date
  count $countOuter

  for $speaker at $pos in $Blog//spreker/string()

  return ($countOuter, $Id, $Datum, $pos,  $speaker)

suffice, or, as a "table",

string-join(
  for $Blog in collection("Blog")
order by $Blog//datum/@date
  let $Id := $Blog/handeling/@id
  let $Datum := $Blog//datum/@date
  count $countOuter

  for $speaker at $pos in $Blog//spreker/string()

  return
string-join(($countOuter, $Id, $Datum, $pos,  $speaker), ', ')
  ,
'')



Re: [basex-talk] RESTXQ generated HTML - unexpected behaviour

2022-01-07 Thread Martin Honnen


Am 07.01.2022 um 10:56 schrieb Hans-Juergen Rennau:

Phantastic, Martin - you made it work! Many thanks!

Could you help me fully understand the reason - so why /exactly/ is
    %output:method("xhtml")

essential? I would have thought that the reason is fully given by the
serialization details. But from what you wrote I gather there is a
second reason, which is the content-type header which is set dependent
on %output-method? After reading your post I also found in the BaseX
documentation:

"The next function, when called, generates XHTML headers, and
|text/html| will be set as content type:"



As far as I have understood the BaseX documentation for REST and RESTXQ,
the default content response type for a GET request is application/xml,
so for your GET where you want to return XHTML to be treated as
text/html, you need to use one of the ways to ensure that the content
response type is text/html, the easiest I have found is to add the

  %output:method("xhtml")

annotation.


Re: [basex-talk] RESTXQ generated HTML - unexpected behaviour

2022-01-06 Thread Martin Honnen


Am 07.01.2022 um 08:39 schrieb Martin Honnen:



Am 07.01.2022 um 01:29 schrieb Hans-Juergen Rennau:

Hello,

I face a problem with RESTXQ of a fairly general character, as it
seems to me.

When the XQuery functions of a RESTXQ application construct HTML
pages, I expect these pages to behave exactly as a static page with
the same content would behave. But sometimes this is not the case.

As an attachment I send an example. The "webapp" folder contains an
XQuery module with a RESTXQ function [2], and the "html" folder
contains an HTML page [3] which is identical to the page generated by
the RESTXQ function [4]. This page has been copied from [1], and it
demonstrates auto completion in an input field.

However, auto completion works only when calling the HTML file; it
does not work when calling the RESTXQ application.

In both cases, the HTML page references a JS file as well as a CSS
file, located in a sibling folder "static". An alert box as well as
the appearance of the page prove that JS and CSS are found and used
in both cases. And yet the behaviour is different ...

~~~

This problem appears to me important, as the trust in RESTXQ would be
damaged if the generated HTML "may or may not" behave as it should.
On the other hand, if the reason of the problem is understood and a
workaround is available, all would be well.



I have not tried your code but if JavaScript fails in one result
document but not in another then one reason could be that the
JavaScript is written for text/html documents (as which static .html
or htm documents are ususally served) while the code does not work
right with XHTML served as application/xml or application/xhtml+xml.

So I would first check whether your RESTXQ where the script doesn't
work is served as text/html or with an XML MIME type like the two ones
I have mentioned, in the latter case I would indeed expect script
attempts like

  a = document.createElement("DIV")

to fail to achieve to create the right element as X(HT)ML is
case-sensitive and works with a namespace so you would rather need

 a = document.createElementNS("http://www.w3.org/1999/xhtml;, "div")

in an X(HT)ML served with an XML mime type context.




So I think your XQuery code lacks %output:method("xhtml") e.g.

  declare
 %rest:path("/demo-autocomplete")
 %rest:GET
    %output:method("xhtml")

function f:demoAutocomplete() as element() {




Re: [basex-talk] RESTXQ generated HTML - unexpected behaviour

2022-01-06 Thread Martin Honnen


Am 07.01.2022 um 01:29 schrieb Hans-Juergen Rennau:

Hello,

I face a problem with RESTXQ of a fairly general character, as it
seems to me.

When the XQuery functions of a RESTXQ application construct HTML
pages, I expect these pages to behave exactly as a static page with
the same content would behave. But sometimes this is not the case.

As an attachment I send an example. The "webapp" folder contains an
XQuery module with a RESTXQ function [2], and the "html" folder
contains an HTML page [3] which is identical to the page generated by
the RESTXQ function [4]. This page has been copied from [1], and it
demonstrates auto completion in an input field.

However, auto completion works only when calling the HTML file; it
does not work when calling the RESTXQ application.

In both cases, the HTML page references a JS file as well as a CSS
file, located in a sibling folder "static". An alert box as well as
the appearance of the page prove that JS and CSS are found and used in
both cases. And yet the behaviour is different ...

~~~

This problem appears to me important, as the trust in RESTXQ would be
damaged if the generated HTML "may or may not" behave as it should. On
the other hand, if the reason of the problem is understood and a
workaround is available, all would be well.



I have not tried your code but if JavaScript fails in one result
document but not in another then one reason could be that the JavaScript
is written for text/html documents (as which static .html or htm
documents are ususally served) while the code does not work right with
XHTML served as application/xml or application/xhtml+xml.

So I would first check whether your RESTXQ where the script doesn't work
is served as text/html or with an XML MIME type like the two ones I have
mentioned, in the latter case I would indeed expect script attempts like

  a = document.createElement("DIV")

to fail to achieve to create the right element as X(HT)ML is
case-sensitive and works with a namespace so you would rather need

 a = document.createElementNS("http://www.w3.org/1999/xhtml;, "div")

in an X(HT)ML served with an XML mime type context.




Re: [basex-talk] BaseX 9.6.4: Tweaks, Fixes & Thank Yous

2021-12-17 Thread Martin Honnen



Am 17.12.2021 um 10:17 schrieb Christian Grün:

We conclude this year with yet another release of BaseX, our XML
framework, database and XQuery processor [1]. The new version contains
new performance tweaks and minor bug fixes, the details of which can
be examined on our GitHub page [2].


Great, a new release to explore during the holiday season. Now waiting
for Saxonica to deliver Saxon Java 11 as another gift for the holiday
season. And then checking to see what breaks if Saxon 11 as an XSLT
processor in BaseX is used to run XSLT 4.



Re: [basex-talk] Didn't know ....

2021-12-07 Thread Martin Honnen



Am 07.12.2021 um 10:16 schrieb Marco Lettere:

Hi all,

Just because "abc" || () returns "abc", it felt natural to me that  should return  but I get 
instead.

This is on a 9.6.1.

I can't recall whether this has always been like that thus it's one of
my xquery shortcomings or if actually something strange is going on
here ...




I would see that as a BaseX bug.



Re: [basex-talk] Output script-element with javascript source code

2021-12-07 Thread Martin Honnen



Am 07.12.2021 um 10:00 schrieb Kristian Kankainen:

Hi all,

Can I somehow control the serialization of element contents? I want to use 
Xquery to generate parts of source code for javascript and put the generated 
code inside a script element on the webpage. Basically this:

define function web:display-graph($term) {
 
 {
 string-join((
   'd3.select("#graph").graphviz().renderDot(',
   "'digraph  {a -> b}'",
   ');'
   ), out:nl())
 }
 
}

But it doesn't work as the > character gets replaced with its corresponding HTML 
entity . Is there a way to circumvent this behaviour?



At which point or how/where do you serialize that "script" element? With
output method "html" the escaping should not take place.



Re: [basex-talk] items of type map(*) cannot be serialized

2021-11-10 Thread Martin Honnen

On 10.11.2021 19:34, Jonathan Robie wrote:

I want to serialize JSON.  Consider the following function:

declare function local:index()
{
  array{ $levinsohn/levinsohn/feature/header ! map {./name :
./description ! string() } }
};

When I run that, I get output that looks like this:

[map {
   "Ambiguous": "Marked but ambiguous constituent order."
}, map {
   "annotations": "Inline annotations."
}
!!! SNIP !!!]

That won't work as output in a REST API, so I want to serialize that
without the map keyword.  I tried to use fn:serialize():

declare function local:index()
{
  array{ $levinsohn/levinsohn/feature/header ! map {./name :
./description ! string() } } ! serialize(.)
};

That gave me this error:

items of type map(*) cannot be serialized


So ... what's the right way to do this?


I would use

  serialize(local:index(), map { 'method' : 'json' })

to serialize the whole array as JSON



Re: [basex-talk] probably a bug

2021-09-02 Thread Martin Honnen

On 02.09.2021 17:22, Rob Stapper wrote:


Consider snippets [1] and [2], both result in false(). That can’t be
right to me.

[1] () = 4

[2] () != 4


The empty sequence is neither equal to nor unequal to the number 4 as it
doesn't contain any item to compare 4 to:

https://www.w3.org/TR/xquery-31/#id-general-comparisons

General comparisons are existentially quantified comparisons that may be
applied to operand sequences of any length.

The result of the comparison is true if and only if there is a pair of
atomic values, one in the first operand sequence and the other in the
second operand sequence, that have the required magnitude relationship.
Otherwise the result of the comparison is false.


Re: [basex-talk] XQuery output without namespace declaration

2021-08-25 Thread Martin Honnen


Am 25.08.2021 um 17:41 schrieb Yann NICOLAS (ABES):


Did you see my other suggestion in the first answer  to try to change
your XQuery code to use

   insert node $record/c ! element { node-name() } {  @*, node() }
into db:open('uk_parlement_ead')/dsc


Oh, i missed it ! Sorry.

It is working ... at the  level :



  http://www.w3.org/2001/XMLSchema-instance;
xmlns:marc="http://www.loc.gov/MARC21/slim"*>



I see, I guess one way would be to write a recursive function you pass
that `c` element to that then recreates any element like in the above
snippet, only recursively e.g.


declare function local:strip-namespaces($node as node()) as node()
{
    typeswitch($node)
  case element()
    return element { node-name($node) } { $node/@*,
$node/node()!local:strip-namespaces(.) }
  default
    return $node

};


and then use e.g.


insert node $record/c ! local:strip-namespaces(.) into
db:open('uk_parlement_ead')/dsc


Hopefully there is an easier way using XQuery update instructions but I
am not good enough with them to know.



Re: [basex-talk] XQuery output without namespace declaration

2021-08-25 Thread Martin Honnen


Am 25.08.2021 um 17:16 schrieb Yann NICOLAS (ABES):


Actually, i am trying to omit the *namespaces*, not the xml
declaration. Sorry for the mistake in my first post, Martin.



Did you see my other suggestion in the first answer  to try to change
your XQuery code to use

   insert node $record/c ! element { node-name() } {  @*, node() } into
db:open('uk_parlement_ead')/dsc





Re: [basex-talk] XQuery output without namespace declaration

2021-08-25 Thread Martin Honnen


Am 25.08.2021 um 15:12 schrieb Yann NICOLAS (ABES):


Hi all,

I am looking for the equivalent instruction of XSLT attribute
@omit-xml-declaration in XQuery.



In the Query prolog you can declare


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

declare option output:method 'xml';
declare option output:omit-xml-declaration 'yes';




My input is :



  http://www.loc.gov/MARC21/slim;
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"*>
    01321nam a22002772a 4500
    
  
    1808001595
  
    
  



My query is :


declare namespace marc="http://www.loc.gov/MARC21/slim;;

for $record in db:open('marcxml_full')/marc/marc:record
return
insert node $record/c into db:open('uk_parlement_ead')/dsc

The ouput is :


http://www.loc.gov/MARC21/slim;
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance; *level="item">
  
    1808001595
  
    

As you can see, there are no marc: elements in this output, hence no
need for the marc: namespace.
How to get rid of @xmlns:marc and xmlns:xsi ?



That seems to be a different issue from the XML declaration, if the
nodes you copy from the one db into the other have a namespace in scope
than that namespace is copied through.

Perhaps

   insert node $record/c ! element { node-name() } {  @*, node() } into
db:open('uk_parlement_ead')/dsc

does what you need.



Re: [basex-talk] BaseX 9.6 - BaseX96.zip - missing? Image not found: /img/c_go.png and Image not found: /img/c_editopen.png

2021-08-19 Thread Martin Honnen

On 20.08.2021 00:04, Martin Honnen wrote:

On 19.08.2021 23:56, Patrick Durusau wrote:


Running ./basexgui

2 image not found messages (omitting the at messages)

Image not found: /img/c_go.png and Image not found: /img/c_editopen.png

On Debian (Buster I think).


On Windows (installed with BaseX96.exe) I see a yellow triangle with an
exclamation mark icon for the "Run query" button in the GUI. That icon
indeed differs from 9.5.

Same for the "Choose directory" button.



It seems both issues are already fixed in the repository :)
https://github.com/BaseXdb/basex/commit/c0c8cfacb0689bb0432d72194c33b8e5301f7449


Re: [basex-talk] BaseX 9.6 - BaseX96.zip - missing? Image not found: /img/c_go.png and Image not found: /img/c_editopen.png

2021-08-19 Thread Martin Honnen

On 19.08.2021 23:56, Patrick Durusau wrote:


Running ./basexgui

2 image not found messages (omitting the at messages)

Image not found: /img/c_go.png and Image not found: /img/c_editopen.png

On Debian (Buster I think).


On Windows (installed with BaseX96.exe) I see a yellow triangle with an
exclamation mark icon for the "Run query" button in the GUI. That icon
indeed differs from 9.5.

Same for the "Choose directory" button.


Re: [basex-talk] Can XQuery return unique values present across multiple databases?

2021-08-13 Thread Martin Honnen


Am 13.08.2021 um 00:12 schrieb Tamara Marnell:
Short question: Is it possible to write an XQuery FLWOR statement that 
can return a set of unique values present across multiple databases?


Long question: Our new website in development displays EAD finding 
aids stored across 45 databases in BaseX. I've built "facet" databases 
that index terms in the EADs from controlled vocabularies like 
subjects, places, personal names, etc. The indexes follow this 
structure, where each EAD node contains a unique identifier:



  
    12345
    67890
  
  
    abcde
  
  {etc.}


In the search interface, users can select multiple facets to apply to 
one search. For example, they could browse database 12 for EADs with 
the subject "Literature" /and/ the place "Oregon," etc.


I currently use the REST server to run an XQuery file that loops 
through each selected facet and prints /all/ EAD IDs for each 
submitted term and database. Then after results are returned, I use 
PHP to count occurences of each EAD and print them only if the total 
count matches the count of facets used.


declare variable $d as xs:string external;
declare variable $f as xs:string external;
let $db_ids := tokenize($d, '\|')
return {
for $facet in tokenize($f, '\|')
  let $split := tokenize($facet, ':')
  let $facet_type := $split[1]
  let $facet_term := $split[2]
  let $facet_db := 'facet-' || $facet_type
  return {
    for $ead in db:open($facet_db)/terms/term[@text=$facet_term and 
@db=$db_ids]/ead

      return $ead
  }
}

So in the hypothetical example above, I'd pass "12" as d (or multiple 
selected databases separated by bars) and 
"subject:Literature|geogname:Oregon" as f, and I'd get back a document 
like:



  
    12345
    67890
  
  
    12345
  


The count of "12345" will equal the count of the user's selected 
facets, so that result will be printed, but 67890 will not.


Is there a more efficient way to do this? I'd prefer the XQuery to 
return only the EADs that meet all criteria, so only 12345 would be 
returned because it's in facet-subject under Literature /and/ in 
facet-geogname under "Oregon," and then I don't have to do any 
post-processing.




I think you can use fold-left to reduce the found eas while selecting them:



let $db_ids := tokenize($d, '\|')
return
    {
    let $facet-maps :=
  fold-left(
    for $facet in tokenize($f, '\|')
  let $split := tokenize($facet, ':')
  let $facet_type := $split[1]
  let $facet_term := $split[2]
  let $facet_db := 'facet-' || $facet_type
    return
  map:merge(
  for $ead in 
db:open($facet_db)/terms/term[@text=$facet_term and @db=$db_ids]/ead
  return map:entry(string($ead), map { 'node' : $ead, 
'type' : $facet_type, 'term' : $facet_term })

  ,
  map { 'duplicates' : 'combine' }
  )
   ,
   map{},
   function($ams, $m) {
   for $m1 in $ams
   return map:remove($m1, map:keys($m1)[not(. = 
map:keys($m))]),

   $m
   }
  )
    return
    for $m in $facet-maps[exists(map:keys(.))]
    let $ead1 := $m?*[1]
    return
    
    {
    $m?*?node
    }
    
    }



Re: [basex-talk] XProc?

2021-08-12 Thread Martin Honnen



Am 12.08.2021 um 13:58 schrieb Jonathan Robie:

What hooks does BaseX provide for XProc?  Where can I find examples of
BaseX use in an XProc pipeline?



Morgana XProc for XProc 1 has support for using BaseX for the p:xquery
step:
https://www.xml-project.com/documentation/morgana-userguide/morganaxproc_enhance/#xquery



Re: [basex-talk] automatically running an unknown number of queries on a variable content set

2021-07-06 Thread Martin Honnen


Am 06.07.2021 um 18:38 schrieb Graydon Saunders:


So the idea is to -- via some automatic process, so "the command line"
-- load a content set into BaseX and then run some arbitrary list of
queries on that content set, returning an aggregated report.

It's important that it's easy to add a query; we expect to be adding
queries as we find new ways for the content to be inappropriate. 
(We're guaranteed it's valid; we are not guaranteed it's sensible, in
the "and just how do you expect to publish forty seven levels of
nested lists?" sense.)

My first thought is to have a directory of individual queries and have
the main query walk through them with xquery:eval(), but there might
be a better way.

Anyone got any suggestions?



Most of the description seems to just fit BaseX command line scripts
https://docs.basex.org/wiki/Commands#Basics. Not sure, however, whether
"an aggregrated report" is easily achieved that way.



Re: [basex-talk] Re: Command Files - string syntax

2021-06-28 Thread Martin Honnen



 
 Not sure, https://docs.basex.org/wiki/Command-Line_Options#Standalone suggests there is a -u command line optionAm 28.06.21, 23:58 schrieb Jonathan Robie :

  
   

 DOH!  Thanks for the help, I seem to be a little dsylexic today ;->
 
  
 
 
  Now it works, but SET WRITEBACK true doesn't seem to be working:
 
 
  
 
 
  DROP DB oshb-morphology
  CREATE DB oshb-morphology
  ADD ./morphhb/wlc
  SET WRITEBACK true
  XQUERY ./xquery/merge-proper-nouns-oshb.xq
  EXPORT ./out
  
  
  
   This query does an update. If I run the same query in the GUI, it works, but not in this ... um ... bxs file.  What do I do to enable updates?
  
 
 
  
 
 
  Jonathan
 

   
  
  
  
   
On Mon, Jun 28, 2021 at 3:57 PM Martin Honnen <martin.hon...@gmx.de> wrote:

   
   
On 28.06.2021 20:54, Jonathan Robie wrote:
 > I decided to try creating some command files to simplify administration:
 >
 > https://docs.basex.org/wiki/Commands#String_Syntax
 > <https://docs.basex.org/wiki/Commands#String_Syntax>
 >
 > I was surprised that this did not work:
 >
 > % cat foo.bsx
 >
 > CREATE DB test
 >
 > ADD TO embedded.xml embedded
 >
 > # run query
 >
 > XQUERY { count(//text()) }
 >
 > CLOSE
 >
 >
 > % basex foo.bsx
 >
 > Stopped at /.../foo.bsx, 1/9:
 >
 > [XPST0003] Unexpected end of query: 'DB test...'.


 I think the suffix of the file needs to be ".bxs" to be treated as a
 command sequence, otherwise it is treated as XQuery code. So you have
 the wrong file suffix.

   
  
 



Re: [basex-talk] Command Files - string syntax

2021-06-28 Thread Martin Honnen

On 28.06.2021 20:54, Jonathan Robie wrote:

I decided to try creating some command files to simplify administration:

https://docs.basex.org/wiki/Commands#String_Syntax


I was surprised that this did not work:

% cat foo.bsx

CREATE DB test

ADD TO embedded.xml embedded

# run query

XQUERY { count(//text()) }

CLOSE


% basex foo.bsx

Stopped at /.../foo.bsx, 1/9:

[XPST0003] Unexpected end of query: 'DB test...'.



I think the suffix of the file needs to be ".bxs" to be treated as a
command sequence, otherwise it is treated as XQuery code. So you have
the wrong file suffix.


Re: [basex-talk] differencing the string value of documents

2021-06-11 Thread Martin Honnen


Am 11.06.2021 um 08:34 schrieb Martin Honnen:



Am 11.06.2021 um 03:06 schrieb Graydon Saunders:


So I have XML documents A and B.

For this purpose, the markup (which is known to be different) is not
relevant; the thing I need to do is prove that all of the text in the
string value of A is present in B in the same order in which it
exists in A.  Document B can have additional text and still be
correct, so it is not sufficient to check if string(A) = string(B). 
(Ideally, B's extra text can be extracted and then compared against
the sources of extra text in the transformation between A and B so as
to confirm that it's at least all plausible new text.)


At least on the string level even XPath 1 comparisons with
substring-before/after should suffice e.g.

  if (string(A) = string(B))

  then "complete match"

  else



Of course contains(string(B), string(A)) would alone suffice to check
for a partial match.


    let $prefix := substring-before(string(B), string(A)),

  $suffix := substring-after(string(B), string(A))

    return if ($suffix != '' or $prefix != '')

    then "partial match"

   else "no match"

I don't know what the "plausible new text" requirement is about or how
to express it.



Re: [basex-talk] differencing the string value of documents

2021-06-11 Thread Martin Honnen


Am 11.06.2021 um 03:06 schrieb Graydon Saunders:


So I have XML documents A and B.

For this purpose, the markup (which is known to be different) is not
relevant; the thing I need to do is prove that all of the text in the
string value of A is present in B in the same order in which it exists
in A.  Document B can have additional text and still be correct, so it
is not sufficient to check if string(A) = string(B).  (Ideally, B's
extra text can be extracted and then compared against the sources of
extra text in the transformation between A and B so as to confirm that
it's at least all plausible new text.)


At least on the string level even XPath 1 comparisons with
substring-before/after should suffice e.g.

  if (string(A) = string(B))

  then "complete match"

  else

    let $prefix := substring-before(string(B), string(A)),

  $suffix := substring-after(string(B), string(A))

    return if ($suffix != '' or $prefix != '')

    then "partial match"

   else "no match"

I don't know what the "plausible new text" requirement is about or how
to express it.



Re: [basex-talk] insert MS SQL server bigint from BaseX via sql:execute-prepared

2021-05-31 Thread Martin Honnen

On 31.05.2021 18:01, Christian Grün wrote:


I have added "long" to the list of supported data types, as well as
"byte" and "bigdecimal" [1]. I hope it works as expected. A new
snapshot is available [2]; your feedback is welcome


Looks great, thanks a (put some bigint here) lot. Turns out my real data
is not yet in shape for what I had planned but at least the long/bigint
column insertion works fine.




[basex-talk] insert MS SQL server bigint from BaseX via sql:execute-prepared

2021-05-31 Thread Martin Honnen


I am trying to use BaseX to enter data from its XML db into an MS SQL
server database, according to
https://docs.microsoft.com/en-us/sql/connect/jdbc/using-basic-data-types?view=sql-server-ver15
the MS SQL server column type bigint is mapped to long in Java.

However, when I try

  {$id}

with BaseX and sql:execute-prepared, I get an error saying [sql:error]
An SQL exception occurred: unsupported type: long

The BaseX documentation
https://docs.basex.org/wiki/SQL_Module#sql:execute-prepared indeed only
lists


attribute  type  {  "int"  |  "string"  |  "boolean"  |  "date"  |  "double"  |
  "float"  |  "short"  |  "time"  |  "timestamp"  |  "sqlxml"  }

as the possible types. Am I out of luck trying to use BaseX that way for
that datatype? Using {$id} the
sql doesn't succeed.



Re: [basex-talk] BUG node comparison

2021-05-26 Thread Martin Honnen


Am 26.05.2021 um 11:03 schrieb ydy...@post.cz:


Dear BaseX,

according to github instructions I’m sending a bug report via email:

Using BaseX 9.5.1, cmd-line “basex.bat -i datafile.xml queryfile.xq” 
leads to no result at all. I’m convinced there should be result 
equivalent to the one of the online xquery tester 
(https://www.videlibri.de/cgi-bin/xidelcgi 
)


For a modified query using string comparison based on fn:path(), BaseX 
gives the expected result.


%%% query begin %%%

let $rootElement := /child::*

for $x in //Section[parent::* != $rootElement]



Are you sure you want the string comparison of the two elements? Or 
rather node identity


   for $x in //Section[not(parent::* is $rootElement)]

?


return fn:path($x)

%%% query end %%%

%%% data begin %%%



    

    

    

    



    

    

    

    

    



%%% data end %%%

%%% modified query begin %%%

let $rootElementPath := fn:path(/child::*)

for $x in //Section[fn:path(parent::*) != $rootElementPath]

return fn:path($x)

%%% query end %%%

Kind regards

Jan Červák



Re: [basex-talk] CSV and automatic encoding detection

2021-05-24 Thread Martin Honnen


Am 24.05.2021 um 09:22 schrieb Kristian Kankainen:

Hi folks,

I am aware that with the HTML module you can let it guess a file's
encoding by itself by providing it in binary format:


If the input encoding is unknown, the data to be processed can be
passed on in its binary representation. The HTML parser will
automatically try to detect the correct encoding:

Query

html:parse(fetch:binary("https://en.wikipedia.org
"))

But is there a way to guess encoding of CSV files? So far I have tried
with the fetch and CSV module with no results. I have a huge bunch of
CSV files and they are all in different encodings. Maybe it is
possible to pipe the content of the fetch:binary to a system command
for guessing the encoding, and use this to read in the csv?



I think both HTML parsers and XML parsers rely on the presence of some
encoding declaration (e.g. a meta charset in HTML or the XML declaration
in XML) to "detect" an encoding; I am not sure CSV has anything like that.

But that is just my understanding of the parser world in general, I
don't know the exact way things work in BaseX.



Re: [basex-talk] Histogramming a large dataset

2021-03-10 Thread Martin Honnen

On 10.03.2021 21:55, Ron Katriel wrote:


The queries you shared terminate quickly and don’t return anything. The
one provided by Graydon does and completes significantly faster. I’m not
sure what accounts for the difference.


I think I missed a step in the paths e.g.


On March 10, 2021 at 3:44:28 PM, Martin Honnen (martin.hon...@gmx.de
<mailto:martin.hon...@gmx.de>) wrote:



> (: 3 items - 52 sec :)
> let $safetyreport := db:open('FAERS')/ichicsr/safetyreport
> for $value in distinct-values($safetyreport/patient/patientsex)
> return concat($value, " ",
> count(index-of($safetyreport/patient/patientsex, $value)))

You could always try whether grouping performs better e.g.

for $ps in db:open('FAERS')/ichicsr/safetyreport/patientsex


should have been

  for $ps in db:open('FAERS')/ichicsr/safetyreport/patient/patientsex


group by $s := $ps
return $s || " " || count($ps)

>
> (: 67 items - 580 sec :)
> let $safetyreport := db:open('FAERS')/ichicsr/safetyreport
> for $value in distinct-values($safetyreport/patient/patientweight ! (.
> div 10.0) ! round(.) ! (. * 10))
> return concat($value, " ",
> count(index-of($safetyreport/patient/patientweight ! (. div 10.0) !
> round(.) ! (. * 10), $value)))


and


for $pw in db:open('FAERS')/ichicsr/safetyreport/patientweight


  for $pw in db:open('FAERS')/ichicsr/safetyreport/patient/patientweight


group by $w := $pw ! (. div 10.0) ! round(.) ! (. * 10))
return $w || " " || count($pw)





Re: [basex-talk] Histogramming a large dataset

2021-03-10 Thread Martin Honnen

On 10.03.2021 21:37, Ron Katriel wrote:

Hi,

I would appreciate your advice on optimizing a query against a large
BaseX (9.2.4) database. It is loaded with data from the FDA’s Adverse
Event Reporting System (FAERS). Currently this is just the 2020 dataset
which comprises 12 documents stored as 308,870,597 nodes (6,565 MB).

The queries below effectively - though not necessarily efficiently -
implement a histogram. The first, which is applied to patient gender
(sex), returns the results (3 items) in 52 seconds:

2 893694
1 583999
0 198

The second does this for patient weight - rounded to the closest 10 lbs
increment. It takes 580 seconds to place the data into 67 bins.
Initially I tried running it on the rounded weights but aborted the run
as it was a taking an inordinate amount of time (there are 217 distinct
weights in the dataset).

Is there a way to improve the performance of this type of query?

Thanks,
Ron


(: 3 items - 52 sec :)
let $safetyreport := db:open('FAERS')/ichicsr/safetyreport
for $value in distinct-values($safetyreport/patient/patientsex)
return concat($value, " ",
count(index-of($safetyreport/patient/patientsex, $value)))


You could always try whether grouping performs better e.g.

  for $ps in db:open('FAERS')/ichicsr/safetyreport/patientsex
  group by $s := $ps
  return $s || " " || count($ps)



(: 67 items - 580 sec :)
let $safetyreport := db:open('FAERS')/ichicsr/safetyreport
for $value in distinct-values($safetyreport/patient/patientweight ! (.
div 10.0) ! round(.) ! (. * 10))
return concat($value, " ",
count(index-of($safetyreport/patient/patientweight ! (. div 10.0) !
round(.) ! (. * 10), $value)))




  for $pw in db:open('FAERS')/ichicsr/safetyreport/patientweight
  group by $w := $pw ! (. div 10.0) ! round(.) ! (. * 10))
  return $w || " " || count($pw)


Re: [basex-talk] file:read-text

2021-01-12 Thread Martin Honnen


On 12.01.2021 13:50, Giuseppe G. A. Celano wrote:

I have found that a few files are not txt, but binary ones. I can open
them with file:read-binary. However, the reference to XML can be
confusing because I am not dealing with XML.



I think https://docs.basex.org/wiki/File_Module#file:read-text suggests
you can use

  file:read-text("file.txt", "UTF-8", true)


and you won't get the error about invalid characters, instead the
returned string contains the Unicode replacement character|FFFD|






On 12. Jan 2021, at 13:41, Martin Honnen mailto:martin.hon...@gmx.de>> wrote:


On 12.01.2021 13:33, Giuseppe G. A. Celano wrote:

Hi,

I am trying to open a bunch of files with file:read-text, but I get
the error [file:io-error] invalid XML character: #0, even I am not
dealing with XML. Any idea why this happens? Thanks!



Perhaps as XQuery strings impose XML rules for allowed characters?
Can you read out the files as binary hex or base64?




Re: [basex-talk] file:read-text

2021-01-12 Thread Martin Honnen


On 12.01.2021 13:33, Giuseppe G. A. Celano wrote:

Hi,

I am trying to open a bunch of files with file:read-text, but I get
the error [file:io-error] invalid XML character: #0, even I am not
dealing with XML. Any idea why this happens? Thanks!



Perhaps as XQuery strings impose XML rules for allowed characters? Can
you read out the files as binary hex or base64?


Re: [basex-talk] Sequence comparison

2020-11-25 Thread Martin Honnen

Am 26.11.2020 um 07:14 schrieb Martin Honnen:

My bad, use
group by $k := $a return {$a}


To describe it clearer, the whole FLOWR should be

for $a in (1,2,3,5)
where $a = (1,3,2,3)
group by $k := $a
return
{$a}



Re: [basex-talk] Re: Sequence comparison

2020-11-25 Thread Martin Honnen



 
 My bad, use group by $k := $a return {$a}-- Diese Nachricht wurde von meinem Android Mobiltelefon mit GMX Mail gesendet.Am 26.11.20, 02:28 schrieb "Giuseppe G. A. Celano" :

  Unfortunately this does not work because, if the second sequence has only one 3 (and the first has two 3), I will still get two 3, while I should get only one.
  
   >
   > Or more FLOWR like
   > for $a in (1,2,3,5,3)
   > where $a . = (1,3,2)
   > group by $o := $a
   > return
   > {$a}
  
  
  
  
  
  
   > On 25. Nov 2020, at 09:11, Martin Honnen  wrote:
   >
   > Am 25.11.2020 um 08:39 schrieb Martin Honnen:
   >> Am 25.11.2020 um 06:37 schrieb Giuseppe G. A. Celano:
   >>
   >>> I have to compare two sequences and find common items, irrespective of
   >>> their positions:
   >>>
   >>> for $a in (1,2,3,5,3)
   >>> for $u in (1,3,2,3)
   >>> where $a = $u
   >>> group by $o := $a
   >>> return
   >>> {$a}
   >>>
   >>> This returns
   >>> 1
   >>> 2
   >>> 3 3 3 3
   >>>
   >>> I would like 3 to be repeated only twice (i.e., each item in the first
   >>> sequence should pair only with one in the second sentence): is there an
   >>> XQuery "trick" for that in the FLOWR _expression_?
   >>
   >> I think
   >>
   >> for $a in (1,2,3,5,3)[. = (1,3,2,3)]
   >> group by $o := $a
   >> return
   >> {$a}
   >>
   >> would do that
   >
   > Or more FLOWR like
   > for $a in (1,2,3,5,3)
   > where $a . = (1,3,2,3)
   > group by $o := $a
   > return
   > {$a}
   >
  
  
 



Re: [basex-talk] Sequence comparison

2020-11-25 Thread Martin Honnen

Am 25.11.2020 um 08:39 schrieb Martin Honnen:

Am 25.11.2020 um 06:37 schrieb Giuseppe G. A. Celano:


I have to compare two sequences and find common items, irrespective of
their positions:

for $a  in (1,2,3,5,3)
for $u  in (1,3,2,3)
where $a = $u
group by $o := $a
return
{$a}

This returns
1
2
3 3 3 3

I would like 3 to be repeated only twice (i.e., each item in the first
sequence should pair only with one in the second sentence): is there an
XQuery "trick" for that in the FLOWR expression?


I think

for $a  in (1,2,3,5,3)[. = (1,3,2,3)]
group by $o := $a
return
{$a}

would do that


Or more FLOWR like
  for $a  in (1,2,3,5,3)
  where $a . = (1,3,2,3)
  group by $o := $a
  return
  {$a}


Re: [basex-talk] Sequence comparison

2020-11-24 Thread Martin Honnen

Am 25.11.2020 um 06:37 schrieb Giuseppe G. A. Celano:


I have to compare two sequences and find common items, irrespective of
their positions:

for $a  in (1,2,3,5,3)
for $u  in (1,3,2,3)
where $a = $u
group by $o := $a
return
{$a}

This returns
1
2
3 3 3 3

I would like 3 to be repeated only twice (i.e., each item in the first
sequence should pair only with one in the second sentence): is there an
XQuery "trick" for that in the FLOWR expression?


I think

for $a  in (1,2,3,5,3)[. = (1,3,2,3)]
group by $o := $a
return
{$a}

would do that



Re: [basex-talk] importing data from powershell

2020-11-17 Thread Martin Honnen



On 18.11.2020 01:47, Nicholas wrote:

for some simple data as:


PS /home/nicholas>
PS /home/nicholas> $data = @{
>> customer = 'something'
>> name = 'whatever'
>> }
PS /home/nicholas>
PS /home/nicholas> ($data | ConvertTo-Xml).OuterXml
namewhatevercustomersomething
PS /home/nicholas>


what would be some different ways of importing this data into BaseX? 
Certainly, the above XML can simply be written to a file, but what
might something, from within powershell,  a bit more automated?




Well, Powershell is .NET based so the BaseX .NET/C# client
https://github.com/BaseXdb/basex/blob/master/basex-api/src/main/c%23/BaseXClient.cs
could be used.



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.



  1   2   >