…that’s it. Another solution is to use fetch:doc:

   fetch:doc($input, { 'stripws': true() })

With XQuery 4, the standard fn:doc function may be extended with an options argument. If so, the fetch namespace prefix can be omitted.



<ykhabins@bellsouth.net> schrieb am Di., 2. Juli 2024, 17:36:
The solution was to add a stripws option.
After that all output XML files are indented properly because causing the
issue whitespaces were removed.
Please see the working properly XQuery below.


(: https://docs.basex.org/main/Options#stripws :)
declare option db:stripws "true";

declare variable $input as xs:string external;
declare variable $output_dir as xs:string external;

for $x at $i in doc($input)/Events/Event
return file:write($output_dir || file:dir-separator() || "event_" || $i ||
".xml", $x
  , map {'method': 'xml', 'indent': 'yes', 'omit-xml-declaration': 'no'})



Regards,
Yitzhak Khabinsky