Re: [basex-talk] RESTXQ generated HTML - unexpected behaviour

2022-01-07 Thread Martin Honnen


Am 07.01.2022 um 10:56 schrieb Hans-Juergen Rennau:

Phantastic, Martin - you made it work! Many thanks!

Could you help me fully understand the reason - so why /exactly/ is
    %output:method("xhtml")

essential? I would have thought that the reason is fully given by the
serialization details. But from what you wrote I gather there is a
second reason, which is the content-type header which is set dependent
on %output-method? After reading your post I also found in the BaseX
documentation:

"The next function, when called, generates XHTML headers, and
|text/html| will be set as content type:"



As far as I have understood the BaseX documentation for REST and RESTXQ,
the default content response type for a GET request is application/xml,
so for your GET where you want to return XHTML to be treated as
text/html, you need to use one of the ways to ensure that the content
response type is text/html, the easiest I have found is to add the

  %output:method("xhtml")

annotation.


Re: [basex-talk] RESTXQ generated HTML - unexpected behaviour

2022-01-07 Thread Hans-Juergen Rennau
 Phantastic, Martin - you made it work! Many thanks!
Could you help me fully understand the reason - so why exactly is
    %output:method("xhtml")
essential? I would have thought that the reason is fully given by the 
serialization details. But from what you wrote I gather there is a second 
reason, which is the content-type header which is set dependent on 
%output-method? After reading your post I also found in the BaseX documentation:
"The next function, when called, generates XHTML headers, and text/html will be 
set as content type:"
Thanks again -Hans-Jürgen




Am Freitag, 7. Januar 2022, 08:54:25 MEZ hat Martin Honnen 
 Folgendes geschrieben:  
 
  

 
 Am 07.01.2022 um 08:39 schrieb Martin Honnen:
  
 


 
 Am 07.01.2022 um 01:29 schrieb Hans-Juergen Rennau:
  
 
 Hello, 
  I face a problem with RESTXQ of a fairly general character, as it seems to 
me. 
  When the XQuery functions of a RESTXQ application construct HTML pages, I 
expect these pages to behave exactly as a static page with the same content 
would behave. But sometimes this is not the case. 
  As an attachment I send an example. The "webapp" folder contains an XQuery 
module with a RESTXQ function [2], and the "html" folder contains an HTML page 
[3] which is identical to the page generated by the RESTXQ function [4]. This 
page has been copied from [1], and it demonstrates auto completion in an input 
field. 
  However, auto completion works only when calling the HTML file; it does not 
work when calling the RESTXQ application. 
  In both cases, the HTML page references a JS file as well as a CSS file, 
located in a sibling folder "static". An alert box as well as the appearance of 
the page prove that JS and CSS are found and used in both cases. And yet the 
behaviour is different ...
  
  ~~~ 
  This problem appears to me important, as the trust in RESTXQ would be damaged 
if the generated HTML "may or may not" behave as it should. On the other hand, 
if the reason of the problem is understood and a workaround is available, all 
would be well. 
   

 
 
I have not tried your code but if JavaScript fails in one result document but 
not in another then one reason could be that the JavaScript is written for 
text/html documents (as which static .html or htm documents are ususally 
served) while the code does not work right with XHTML served as application/xml 
or application/xhtml+xml.
 
So I would first check whether your RESTXQ where the script doesn't work is 
served as text/html or with an XML MIME type like the two ones I have 
mentioned, in the latter case I would indeed expect script attempts like
 
  a = document.createElement("DIV") 
 
 
to fail to achieve to create the right element as X(HT)ML is case-sensitive and 
works with a namespace so you would rather need
 
 a = document.createElementNS("http://www.w3.org/1999/xhtml";, "div")
 
in an X(HT)ML served with an XML mime type context.
 

 
 

 
 
So I think your XQuery code lacks %output:method("xhtml") e.g.
 
 
  declare 
  %rest:path("/demo-autocomplete")
  %rest:GET
     %output:method("xhtml")
 
function f:demoAutocomplete() as element() {
 
 

 
 

 
   

Re: [basex-talk] RESTXQ generated HTML - unexpected behaviour

2022-01-06 Thread Martin Honnen


Am 07.01.2022 um 08:39 schrieb Martin Honnen:



Am 07.01.2022 um 01:29 schrieb Hans-Juergen Rennau:

Hello,

I face a problem with RESTXQ of a fairly general character, as it
seems to me.

When the XQuery functions of a RESTXQ application construct HTML
pages, I expect these pages to behave exactly as a static page with
the same content would behave. But sometimes this is not the case.

As an attachment I send an example. The "webapp" folder contains an
XQuery module with a RESTXQ function [2], and the "html" folder
contains an HTML page [3] which is identical to the page generated by
the RESTXQ function [4]. This page has been copied from [1], and it
demonstrates auto completion in an input field.

However, auto completion works only when calling the HTML file; it
does not work when calling the RESTXQ application.

In both cases, the HTML page references a JS file as well as a CSS
file, located in a sibling folder "static". An alert box as well as
the appearance of the page prove that JS and CSS are found and used
in both cases. And yet the behaviour is different ...

~~~

This problem appears to me important, as the trust in RESTXQ would be
damaged if the generated HTML "may or may not" behave as it should.
On the other hand, if the reason of the problem is understood and a
workaround is available, all would be well.



I have not tried your code but if JavaScript fails in one result
document but not in another then one reason could be that the
JavaScript is written for text/html documents (as which static .html
or htm documents are ususally served) while the code does not work
right with XHTML served as application/xml or application/xhtml+xml.

So I would first check whether your RESTXQ where the script doesn't
work is served as text/html or with an XML MIME type like the two ones
I have mentioned, in the latter case I would indeed expect script
attempts like

  a = document.createElement("DIV")

to fail to achieve to create the right element as X(HT)ML is
case-sensitive and works with a namespace so you would rather need

 a = document.createElementNS("http://www.w3.org/1999/xhtml";, "div")

in an X(HT)ML served with an XML mime type context.




So I think your XQuery code lacks %output:method("xhtml") e.g.

  declare
 %rest:path("/demo-autocomplete")
 %rest:GET
    %output:method("xhtml")

function f:demoAutocomplete() as element() {




Re: [basex-talk] RESTXQ generated HTML - unexpected behaviour

2022-01-06 Thread Martin Honnen


Am 07.01.2022 um 01:29 schrieb Hans-Juergen Rennau:

Hello,

I face a problem with RESTXQ of a fairly general character, as it
seems to me.

When the XQuery functions of a RESTXQ application construct HTML
pages, I expect these pages to behave exactly as a static page with
the same content would behave. But sometimes this is not the case.

As an attachment I send an example. The "webapp" folder contains an
XQuery module with a RESTXQ function [2], and the "html" folder
contains an HTML page [3] which is identical to the page generated by
the RESTXQ function [4]. This page has been copied from [1], and it
demonstrates auto completion in an input field.

However, auto completion works only when calling the HTML file; it
does not work when calling the RESTXQ application.

In both cases, the HTML page references a JS file as well as a CSS
file, located in a sibling folder "static". An alert box as well as
the appearance of the page prove that JS and CSS are found and used in
both cases. And yet the behaviour is different ...

~~~

This problem appears to me important, as the trust in RESTXQ would be
damaged if the generated HTML "may or may not" behave as it should. On
the other hand, if the reason of the problem is understood and a
workaround is available, all would be well.



I have not tried your code but if JavaScript fails in one result
document but not in another then one reason could be that the JavaScript
is written for text/html documents (as which static .html or htm
documents are ususally served) while the code does not work right with
XHTML served as application/xml or application/xhtml+xml.

So I would first check whether your RESTXQ where the script doesn't work
is served as text/html or with an XML MIME type like the two ones I have
mentioned, in the latter case I would indeed expect script attempts like

  a = document.createElement("DIV")

to fail to achieve to create the right element as X(HT)ML is
case-sensitive and works with a namespace so you would rather need

 a = document.createElementNS("http://www.w3.org/1999/xhtml";, "div")

in an X(HT)ML served with an XML mime type context.