copy/modify/return and the base URI
Thursday, 24 August 2023 · 6 messages · last reply 28 Aug 2023
HR
Hans-Juergen Rennau24 Aug 2023 18:11 #
Dear BaseX team,
I seem to remember that in earlier versions of BaseX a copy/modify/return did not change the base URI of the processed document. However, now it is lost, or more precisely, replaced with the static base URI of the processing XQuery module. Am I mistaken? At any rate it would be very desirable for copy/modify/return to preserve the base URI of the processed document or fragment.
Kind regards,Hans-Jürgen
CG
Christian Grün28 Aug 2023 10:35 #
Hi Hans-Jürgen,
The following query gives me true:
(: doc.xml :)
<xml/>
(: query.xq :)
let $doc := doc('doc.xml')
let $copy := copy $d := $doc modify () return $d
return deep-equal(base-uri($doc), base-uri($copy))Could you please provide us with a little self-contained example?
Thanks in advance,
Christian
Quoted text · Hans-Juergen Rennau · 16 lines
On Thu, Aug 24, 2023 at 6:12 PM Hans-Juergen Rennau <hrennau at yahoo.de> wrote: > Dear BaseX team, > > I seem to remember that in earlier versions of BaseX a copy/modify/return > did not change the base URI of the processed document. However, now it is > lost, or more precisely, replaced with the static base URI of the > processing XQuery module. > > Am I mistaken? At any rate it would be very desirable for > copy/modify/return to preserve the base URI of the processed document or > fragment. > > Kind regards, > Hans-Jürgen >
HR
Hans-Juergen Rennau28 Aug 2023 15:42 #
Dear Christian,
after manifold motions making little speed it dawned on me that the problem occurs if the node in question is an element node, rather than the document node, as demonstrated by this query:
declare namespace f="http://www.parsqube.de";
declare function f:prettyNode($n as node()) as node()? {
copy $n_ := $n
modify delete nodes $n_//text()[not(matches(., '\S'))][../*]
return $n_
};
let $doc := doc('doc.xml')
let $dnode1 := $doc
let $dnode2 := f:prettyNode($dnode1)
let $enode1 := $doc/*
let $enode2 := f:prettyNode($enode1)
return (
'Input document base URI: '||$dnode1/base-uri(.),
'Output document base URI: '||$dnode1/base-uri(.),
'',
'Input element base URI: '||$enode1/base-uri(.),
'Output element base URI: '||$enode2/base-uri(.)
)Output:
Input document base URI: file:///C:/Projects/tableman/work/doc.xml Output document base URI: file:///C:/Projects/tableman/work/doc.xml
Input element base URI: file:///C:/Projects/tableman/work/doc.xml Output element base URI: file:///C:/Projects/tableman/work/test-pretty-node.xq
Greetings -
Hans-Jürgen
Am Montag, 28. August 2023 um 10:35:48 MESZ hat Christian Grün <christian.gruen at gmail.com> Folgendes geschrieben:
Hi Hans-Jürgen,
The following query gives me true:
(: doc.xml :)
<xml/>
(: query.xq :)
let $doc := doc('doc.xml')
let $copy := copy $d := $doc modify () return $d
return deep-equal(base-uri($doc), base-uri($copy))Could you please provide us with a little self-contained example?
Thanks in advance,
Christian
Quoted text · Hans-Juergen Rennau · 12 lines
On Thu, Aug 24, 2023 at 6:12 PM Hans-Juergen Rennau <hrennau at yahoo.de> wrote: > Dear BaseX team, > > > I seem to remember that in earlier versions of BaseX a copy/modify/return did not change the base URI of the processed document. However, now it is lost, or more precisely, replaced with the static base URI of the processing XQuery module. > > > Am I mistaken? At any rate it would be very desirable for copy/modify/return to preserve the base URI of the processed document or fragment. > > > Kind regards, > Hans-Jürgen
CG
Christian Grün28 Aug 2023 16:11 #
Quoted text · Hans-Juergen Rennau · 5 lines
> > after manifold motions making little speed it dawned on me that the > problem occurs if the node in question is an element node, rather than the > document node, as demonstrated by this query: >
Thanks. This behavior is compliant with the spec: A copied element loses its reference to the document node providing the base URI.
Hope this helps,
Christian
HR
Hans-Juergen Rennau28 Aug 2023 16:39 #
A pity (for me), because I need to preserve the information about an element's origin without changing the element by adding a clumsy @xml:base. Out of luck.
Kind regards,Hans-Jürgen
Am Montag, 28. August 2023 um 16:11:56 MESZ hat Christian Grün <christian.gruen at gmail.com> Folgendes geschrieben:
after manifold motions making little speed it dawned on me that the problem occurs if the node in question is an element node, rather than the document node, as demonstrated by this query:
Thanks. This behavior is compliant with the spec: A copied element loses its reference to the document node providing the base URI.
Hope this helps,Christian
CG
Christian Grün28 Aug 2023 16:44 #
The restriction goes back to the XML standard:
https://www.w3.org/TR/xmlbase/#granularity
Quoted text · Hans-Juergen Rennau · 27 lines
Hans-Juergen Rennau <hrennau at yahoo.de> schrieb am Mo., 28. Aug. 2023, 16:39: > A pity (for me), because I need to preserve the information about an > element's origin without changing the element by adding a clumsy @xml:base. > > Out of luck. > > Kind regards, > Hans-Jürgen > > > > Am Montag, 28. August 2023 um 16:11:56 MESZ hat Christian Grün < > christian.gruen at gmail.com> Folgendes geschrieben: > > > after manifold motions making little speed it dawned on me that the > problem occurs if the node in question is an element node, rather than the > document node, as demonstrated by this query: > > > Thanks. This behavior is compliant with the spec: A copied element loses > its reference to the document node providing the base URI. > > Hope this helps, > Christian > >
Written for BaseX 10.7. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery