Develop a module, HOWTO
Friday, 25 February 2022 · 4 messages
BE
Ben Engbers25 Feb 2022 14:25 #
Hi,
I know that it is possible to create a module with functions (I have even done that once), but I can't find the documentation anymore on how to do that.
Could please someone provide the URL to this information?
Thanks,
Ben Engbers
BE
The link to expath is new to me!
Thanx
Ben
Quoted text · Bridger Dyson-Smith · 31 lines
Op 25-02-2022 om 14:35 schreef Bridger Dyson-Smith: > Hi Ben, > > > On Fri, Feb 25, 2022 at 8:25 AM Ben Engbers <Ben.Engbers at be-logical.nl > <mailto:Ben.Engbers at be-logical.nl>> wrote: > > Hi, > > I know that it is possible to create a module with functions (I have > even done that once), but I can't find the documentation anymore on how > to do that. > Could please someone provide the URL to this information? > > Here is the specification: http://expath.org/spec/pkg > <http://expath.org/spec/pkg> > and the BaseX-specific documentation: > https://docs.basex.org/wiki/Repository > <https://docs.basex.org/wiki/Repository> > > If those aren't the pages you're thinking of, please say! :) > > Thanks, > > Ben Engbers > > > HTH > > best, > Bridger
BD
Hi Ben,
Quoted text · Ben Engbers · 10 lines
On Fri, Feb 25, 2022 at 8:25 AM Ben Engbers <Ben.Engbers at be-logical.nl> wrote: > Hi, > > I know that it is possible to create a module with functions (I have > even done that once), but I can't find the documentation anymore on how > to do that. > Could please someone provide the URL to this information? > > Here is the specification: http://expath.org/spec/pkg
and the BaseX-specific documentation: https://docs.basex.org/wiki/Repository
If those aren't the pages you're thinking of, please say! :)
Thanks,
Quoted text · Ben Engbers · 1 line
>
Ben Engbers
Quoted text · Ben Engbers · 1 line
>
HTH
best,
Bridger
BD
Bridger Dyson-Smith25 Feb 2022 15:43 #
Ben,
Apologies - I think I misread your email (and let some things I was thinking of steer the linking!).
For an XQuery module; e.g.
utilities.xqm
xquery version "3.1";
module namespace utils = "http://canofbees.org/ns/xquery/utilities";
declare function utils:atty(
$att as attribute()
) as xs:string* {
"[@" || name($att) || "='" || data($att) || "']"
};
declare function utils:pathing(
$result as xs:string,
$node as node()
) {
concat(
$result, "/"[$result], name($node),
$node/@* ! utils:atty(.) => string-join("")
)
};
declare function utils:build-path(
$nodes as node()*
) as xs:string* {
distinct-values(
$nodes//* ! fold-left(ancestor-or-self::*, '', utils:pathing(?, ?))
)
};and is called from an XQuery by:
xquery version "3.1";
import module namespace utils = "http://canofbees.org/ns/xquery/utilities";
declare variable $input :=
<t>
<a>one</a>
<b i="two"/>
</t>;
utils:build-path($input)I have this particular module installed in my $BASEX/repo directory - more on that in the packaging link from earlier.
Hope that's more helpful :) (and closer to the mark!)
Best,
Bridger
Quoted text · Bridger Dyson-Smith · 32 lines
On Fri, Feb 25, 2022 at 8:35 AM Bridger Dyson-Smith <bdysonsmith at gmail.com> wrote: > Hi Ben, > > > On Fri, Feb 25, 2022 at 8:25 AM Ben Engbers <Ben.Engbers at be-logical.nl> > wrote: > >> Hi, >> >> I know that it is possible to create a module with functions (I have >> even done that once), but I can't find the documentation anymore on how >> to do that. >> Could please someone provide the URL to this information? >> >> Here is the specification: http://expath.org/spec/pkg > and the BaseX-specific documentation: > https://docs.basex.org/wiki/Repository > > If those aren't the pages you're thinking of, please say! :) > > Thanks, >> > > Ben Engbers >> > > HTH > > best, > Bridger >
Written for BaseX 9.6. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery