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

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

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

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

I know, how to construct nodes with simple expressions, using the element
constructors, however I am interested in the 'non-updating updating' (and
how to call them differently, lol) expressions.

-- 
Minden jót, all the best, Alles Gute,
Andreas Mixich


Re: [basex-talk] Passing through entities unchanged when serializing

2019-09-09 Thread Bridger Dyson-Smith
Ha ha, awesome Liam! Thank you for clarifying!

Best,
Bridger


On Mon, Sep 9, 2019 at 9:37 PM Liam R. E. Quin 
wrote:

> On Tue, 2019-09-10 at 02:59 +0200, Andreas Mixich wrote:
> > I wonder why the serialization behaves that way. It does not make
> > sense to
> > me. If a user has the need to escape XML, it should be thorough,
> > shouldn't it?
>
> XML entities are expanded by he XML parser, so by the time XQuery (or
> XSLT) sees the document they are gone.
>
> Consider an entity like
>  "blackgreySteven on>">
>
> 
>
> It'd be really complex to have that visible to XPath and to have to
> write, e.g.
> /students/entity(*)/person
>
> If it's an external parsed entity it's visible in that the base-uri
> property changes, but that's all.
>
> Character entities like  (ŗ) are just special cases of
> general entities, and XML does not distinguish them. I wish it did, but
> we never got back to that work after publishing XML 1.0.
>
> Liam
>
> --
> Liam Quin, https://www.delightfulcomputing.com/
> Available for XML/Document/Information Architecture/XSLT/
> XSL/XQuery/Web/Text Processing/A11Y training, work & consulting.
> Web slave for vintage clipart http://www.fromoldbooks.org/
>
>


Re: [basex-talk] Passing through entities unchanged when serializing

2019-09-09 Thread Andreas Mixich
On Tue, Sep 10, 2019 at 3:37 AM Liam R. E. Quin 
wrote:

> XML entities are expanded by he XML parser, so by the time XQuery (or
> XSLT) sees the document they are gone.
>

Ah, yes, I totally forgot about that! Thanks for clarification!


Re: [basex-talk] Passing through entities unchanged when serializing

2019-09-09 Thread Liam R. E. Quin
On Tue, 2019-09-10 at 02:59 +0200, Andreas Mixich wrote:
> I wonder why the serialization behaves that way. It does not make
> sense to
> me. If a user has the need to escape XML, it should be thorough,
> shouldn't it?

XML entities are expanded by he XML parser, so by the time XQuery (or
XSLT) sees the document they are gone.

Consider an entity like
blackgreySteven">



It'd be really complex to have that visible to XPath and to have to
write, e.g.
/students/entity(*)/person

If it's an external parsed entity it's visible in that the base-uri
property changes, but that's all.

Character entities like  (ŗ) are just special cases of
general entities, and XML does not distinguish them. I wish it did, but
we never got back to that work after publishing XML 1.0.

Liam

-- 
Liam Quin, https://www.delightfulcomputing.com/
Available for XML/Document/Information Architecture/XSLT/
XSL/XQuery/Web/Text Processing/A11Y training, work & consulting.
Web slave for vintage clipart http://www.fromoldbooks.org/



Re: [basex-talk] Passing through entities unchanged when serializing

2019-09-09 Thread Bridger Dyson-Smith
Hi Andreas -
I'm not sure (way outside of my wheelhouse :), but I think because
arbitrary serialization can generate invalid XML, so having a character map
makes the possible invalidity explicit?
Now that I've typed that, I'm not sure if that captures the rational or
not. :) In any case, here's what the specifications have to say[1].

Best,
Bridger

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



On Mon, Sep 9, 2019 at 9:00 PM Andreas Mixich 
wrote:

> I wonder why the serialization behaves that way. It does not make sense to
> me. If a user has the need to escape XML, it should be thorough, shouldn't
> it?
>
> On Mon, Sep 9, 2019 at 10:47 PM Liam R. E. Quin 
> wrote:
>
>> On Mon, 2019-09-09 at 15:04 +0200, Andreas Mixich wrote:
>> > when serializing a string, that contains literal XML with entities,
>> > how do I pass through those entities unchanged?
>>
>> One way is to use a character map, as Bridger Dyson-Smith described.
>>
>> Sometimes another way can be to have a version of the DTD in which the
>> replacement text of the entity marks the presence of the entity, e.g.
>> 
>> but this will affect full-text searching of course.
>>
>> Liam
>>
>> --
>> Liam Quin, https://www.delightfulcomputing.com/
>> Available for XML/Document/Information Architecture/XSLT/
>> XSL/XQuery/Web/Text Processing/A11Y training, work & consulting.
>> Barefoot Webslave for old illustrations  http://www.fromoldbooks.org/
>>
>>
>
> --
> Minden jót, all the best, Alles Gute,
> Andreas Mixich
>


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

2019-09-09 Thread Andreas Mixich
Thanks a lot!

So it seems, I must give the node a new identity instead of just modifying
the old identity.

On Mon, Sep 9, 2019 at 10:41 PM Martin Honnen  wrote:

> On 09.09.2019 20:35, Martin Honnen wrote:
> > On 09.09.2019 20:30, Andreas Mixich wrote:
> >> Hi,
> >>
> >> copy $c := ipsum dolor sit amet
> >> modify insert node namespace {"lipsum"} {"lorem-ipsum"} into $c
> >> return $c
> >>
> >> Expected result:
> >>
> >> ipsum dolor sit
> >> amet
> >
> >
> > The namespace is part of the name of a node so you need to rename the
> > node(s) in a namespace if you want to change the namespace
>
> Your example would be
>
> copy $c := ipsum dolor sit amet
> modify rename node $c as QName("lorem-ipsum", "lipsum:" || local-name($c))
> return $c
>
>
>

-- 
Minden jót, all the best, Alles Gute,
Andreas Mixich


Re: [basex-talk] Passing through entities unchanged when serializing

2019-09-09 Thread Andreas Mixich
I wonder why the serialization behaves that way. It does not make sense to
me. If a user has the need to escape XML, it should be thorough, shouldn't
it?

On Mon, Sep 9, 2019 at 10:47 PM Liam R. E. Quin 
wrote:

> On Mon, 2019-09-09 at 15:04 +0200, Andreas Mixich wrote:
> > when serializing a string, that contains literal XML with entities,
> > how do I pass through those entities unchanged?
>
> One way is to use a character map, as Bridger Dyson-Smith described.
>
> Sometimes another way can be to have a version of the DTD in which the
> replacement text of the entity marks the presence of the entity, e.g.
> 
> but this will affect full-text searching of course.
>
> Liam
>
> --
> Liam Quin, https://www.delightfulcomputing.com/
> Available for XML/Document/Information Architecture/XSLT/
> XSL/XQuery/Web/Text Processing/A11Y training, work & consulting.
> Barefoot Webslave for old illustrations  http://www.fromoldbooks.org/
>
>

-- 
Minden jót, all the best, Alles Gute,
Andreas Mixich


Re: [basex-talk] Passing through entities unchanged when serializing

2019-09-09 Thread Liam R. E. Quin
On Mon, 2019-09-09 at 15:04 +0200, Andreas Mixich wrote:
> when serializing a string, that contains literal XML with entities,
> how do I pass through those entities unchanged?

One way is to use a character map, as Bridger Dyson-Smith described.

Sometimes another way can be to have a version of the DTD in which the
replacement text of the entity marks the presence of the entity, e.g.

but this will affect full-text searching of course.

Liam

-- 
Liam Quin, https://www.delightfulcomputing.com/
Available for XML/Document/Information Architecture/XSLT/
XSL/XQuery/Web/Text Processing/A11Y training, work & consulting.
Barefoot Webslave for old illustrations  http://www.fromoldbooks.org/



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

2019-09-09 Thread Martin Honnen

On 09.09.2019 20:35, Martin Honnen wrote:

On 09.09.2019 20:30, Andreas Mixich wrote:

Hi,

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

Expected result:

ipsum dolor sit
amet



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


Your example would be

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




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

2019-09-09 Thread Martin Honnen

On 09.09.2019 20:30, Andreas Mixich wrote:

Hi,

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

Expected result:

ipsum dolor sit amet



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

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

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


[basex-talk] XQuery Update and Namespace Manipulation

2019-09-09 Thread Andreas Mixich
Hi,

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

Expected result:

ipsum dolor sit amet

but I get

ipsum dolor sit amet

copy $c := ipsum dolor sit amet
modify replace node $c/namespace-node() with namespace {"lipsum"}
{"lorem-ipsum"}
return $c

Here I get an error: [XQST0134] Namespace axis is not supported.

How can I change namespaces for nodes with the simple update expressions?

For background: I try to implement a function:

declare function local:add-namespaces-to-nodes(
  $nodes as element()*,
  $namespaces as array(*)*)
  as element()*
{
  for $namespace in $namespaces
  for $node in $nodes
  return copy $c := $node
 modify insert node (namespace {$namespace(1)} {$namespace(2)})
into $c
 return $c
};

Thanks!

-- 
Minden jót, all the best, Alles Gute,
Andreas Mixich


Re: [basex-talk] Passing through entities unchanged when serializing

2019-09-09 Thread Bridger Dyson-Smith
Hi Andreas -

Have you tried using different serialization options? I.e.,
serialize.xq:
```
declare option output:method "xml";
declare option output:parameter-document "map.xml";
declare variable $input := "Lorem ipsum,  dolor sit amet.";
serialize($input)
```

map.xml:
```
http://www.w3.org/2010/xslt-xquery-serialization;>
  

  

```

When run in the BaseX GUI, I get:
`lt;pgt;Lorem ipsum,  dolor sit amet.lt;/pgt;`,
might be closer?

I think you might have been experiencing the default 'basex' serialization
option (see [1] for more).
Hope that helps.
Best,
Bridger

[1] http://docs.basex.org/wiki/Serialization

On Mon, Sep 9, 2019 at 9:05 AM Andreas Mixich 
wrote:

> Hi,
>
> when serializing a string, that contains literal XML with entities, how do
> I pass through those entities unchanged?
> Example:
>
> let $input := "Lorem ipsum  dolor sit amet "
> return serialize($input)
>
> results in:
>
> pLorem ipsum dolor sit amet, ' consectetur adipisicing
> elit./p
>
> but I want:
>
> pLorem ipsum dolor sit amet,  consectetur adipisicing
> elit./p
>
> --
> Minden jót, all the best, Alles Gute,
> Andreas Mixich
>


[basex-talk] Passing through entities unchanged when serializing

2019-09-09 Thread Andreas Mixich
Hi,

when serializing a string, that contains literal XML with entities, how do
I pass through those entities unchanged?
Example:

let $input := "Lorem ipsum  dolor sit amet "
return serialize($input)

results in:

pLorem ipsum dolor sit amet, ' consectetur adipisicing
elit./p

but I want:

pLorem ipsum dolor sit amet,  consectetur adipisicing
elit./p

-- 
Minden jót, all the best, Alles Gute,
Andreas Mixich