Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namespace-Problem following/following-sibling #3404

Open
lmaylein opened this issue May 7, 2020 · 3 comments
Open

Namespace-Problem following/following-sibling #3404

lmaylein opened this issue May 7, 2020 · 3 comments
Labels
investigate issues being looked at

Comments

@lmaylein
Copy link

lmaylein commented May 7, 2020

Given XML file:

<TEI xmlns="http://www.tei-c.org/ns/1.0" xmlns:hei="https://digi.ub.uni-heidelberg.de/schema/tei/heiEDITIONS">

   ...

   <milestone ana="hc:Chapter" n="5" xml:id="H_ep5" spanTo="#end.H_ep5"/>
   <milestone ana="hc:Heading" resp="hc:Editor" xml:lang="en" spanTo="#end.head.H_ep5.en"/>Tiberius<anchor xml:id="end.head.H_ep5.en"/>
   <milestone ana="hc:Heading" resp="hc:Editor" xml:lang="de" spanTo="#end.head.H_ep5.de"/>Tiberius<anchor xml:id="end.head.H_ep5.de"/>

The following if-condition is not recognized as fulfilled for the two text-nodex "Tiberius":

if ($node/following::tei:anchor[@xml:id=substring($node/preceding::tei:milestone[@resp='hc:Editor'][1]/@spanTo,2)]) then text {''}
else $node

If I remove the (default) tei namespace, the if-condition is recognized as fulfilled (as it should be).
But this is unfortunately very slow, because no indexes can be used.

if ($node/following::*:anchor[@xml:id=substring($node/preceding::tei:milestone[@resp='hc:Editor'][1]/@spanTo,2)]) then text {''}

or

if ($node/following::*[local-name()='anchor'][@xml:id=substring($node/preceding::tei:milestone[@resp='hc:Editor'][1]/@spanTo,2)]) then text {''}

Same problem if I use following-sibling instead of following.

Context (please always complete the following information):

  • OS: Ubuntu 18.0.4
  • eXist-db version: 5.2.0
  • Java Version OpenJDK 1.8.0_252
@triage-new-issues triage-new-issues bot added the triage issue needs to be investigated label May 7, 2020
@joewiz
Copy link
Member

joewiz commented May 8, 2020

@lmaylein I am not able to reproduce the problem in your report. The conditional statement evaluates as true in the following query, returning "found it!":

xquery version "3.1";

declare namespace tei="http://www.tei-c.org/ns/1.0";

let $doc := 
    document { 
        <TEI xmlns="http://www.tei-c.org/ns/1.0" xmlns:hei="https://digi.ub.uni-heidelberg.de/schema/tei/heiEDITIONS">
            <milestone ana="hc:Chapter" n="5" xml:id="H_ep5" spanTo="#end.H_ep5"/>
            <milestone ana="hc:Heading" resp="hc:Editor" xml:lang="en" spanTo="#end.head.H_ep5.en"/>Tiberius<anchor xml:id="end.head.H_ep5.en"/>
            <milestone ana="hc:Heading" resp="hc:Editor" xml:lang="de" spanTo="#end.head.H_ep5.de"/>Tiberius<anchor xml:id="end.head.H_ep5.de"/>
        </TEI> 
    }
let $node := $doc/tei:TEI//text()[1]
return
    if ($node/following::tei:anchor[@xml:id=substring($node/preceding::tei:milestone[@resp='hc:Editor'][1]/@spanTo,2)]) then
        "found it!"
    else
        "didn't find it :("

Can you provide a self-contained query like this that demonstrates the problem?

@joewiz joewiz added the investigate issues being looked at label May 8, 2020
@triage-new-issues triage-new-issues bot removed the triage issue needs to be investigated label May 8, 2020
@lmaylein
Copy link
Author

lmaylein commented May 9, 2020

Yes, I am no longer sure that this is really a namespace problem. I tried to extract a self-contained example from the complex application. In doing so I came across the following problem, which may be related to my original problem. I may also have misunderstood xpath here.

Here is my self-contained and simplified query:

xquery version "3.1";

declare namespace tei="http://www.tei-c.org/ns/1.0";

declare function local:transform-to-html($nodes as node()*)
as item ()*
{
    for $node in $nodes
    return
        typeswitch ($node)
            case text() return
                if ($node/following::tei:anchor[1][@xml:id=substring($node/preceding::tei:milestone[1][@resp='hc:Editor']/@spanTo,2)])
                    then element x1 {$node, element compare {concat($node/following::tei:anchor[1]/@xml:id,'-',$node/preceding::tei:milestone[1][@resp='hc:Editor']/@spanTo)}}
                    else element x2 {$node}
            default
                return local:transform-to-html($node/node())
};

let $doc := document {
<TEI xmlns="http://www.tei-c.org/ns/1.0" xmlns:hei="https://digi.ub.uni-heidelberg.de/schema/tei/heiEDITIONS">
  <sourceDoc>
    <surface ana="hc:Page" n="1r" xml:id="H_1r">
      <zone xml:id="H_1r-a" ana="hc:Column">
        <milestone ana="hc:Chapter" n="1" xml:id="H_ep1" spanTo="#c"/>
        <milestone ana="hc:Heading" resp="hc:Editor" xml:lang="en" spanTo="#a"/>Prologue<anchor xml:id="a"/>
        <milestone ana="hc:Heading" resp="hc:Editor" xml:lang="de" spanTo="#b"/>Prolog<anchor xml:id="b"/>
        <line xml:id="l_H_1r-a.line_1" n="1">IN des almechtigen gotiſ minnen.</line>
        <anchor xml:id="c"/>
      </zone>
    </surface>
  </sourceDoc>
</TEI>
}

let $node := $doc/tei:TEI//tei:sourceDoc
return element div {local:transform-to-html($node/node())}

This produces:

<div>
<x1>
Prologue
<compare>a-#a</compare>
</x1>
<x1>
Prolog
<compare>b-#b</compare>
</x1>
<x1>
IN des almechtigen gotiſ minnen.
<compare>c-#b</compare>
</x1>
</div>

But in my opinion the result should be the following.
The if condition should not be fulfilled.

<div>
<x1>
Prologue
<compare>a-#a</compare>
</x1>
<x1>
Prolog
<compare>b-#b</compare>
</x1>
<x2>IN des almechtigen gotiſ minnen.</x2>
</div>

If I change the if condition to

if ($node/following::tei:anchor[1]/@xml:id=substring($node/preceding::tei:milestone[1][@resp='hc:Editor']/@spanTo,2))

every thing works as expected.
Am I wrong?

@jakub-simek
Copy link

I've checked the behavior of @lmaylein's self-contained query in two different processors out of Oxygen.

The built-in Saxon-HE XQuery 9.8.0.12 processor gives this (correct) result:

<div>
   <x1>Prologue<compare>a-#a</compare>
   </x1>
   <x1>Prolog<compare>b-#b</compare>
   </x1>
   <x2>IN des almechtigen gotiſ minnen.</x2>
</div> 

But if processed by the eXist-db (5.2) XQuery engine the result is:

<div>
   <x1>Prologue<compare>a-#a</compare>
   </x1>
   <x1>Prolog<compare>b-#b</compare>
   </x1>
   <x1>IN des almechtigen gotiſ minnen.<compare>c-#b</compare>
   </x1>
</div>

The eXist-db XQuery engine seems to have a problem dealing with a predicate on the "following" axis correctly, or am I wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigate issues being looked at
Projects
None yet
Development

No branches or pull requests

3 participants