Page 1 of 1

Special entity & breaks in custom refactoring XQuery Update operation

Posted: Tue Aug 28, 2018 4:04 pm
by dnl
My XML file contains two predefined XML entities: """ and "&".
I am confused by the following behaviour:

* when I run my XQU script using a transformation scenario, the entities are untouched (= everything is OK)
* when I run my XQU script using a custom refactoring operation, the entities are expanded. This leads to my XML not well-formed ("&" is changed to "&")

I have followed the instructions on: https://www.oxygenxml.com/doc/versions/ ... _operation

How can I run an XQU script using a custom refactoring operation that leaves the entities untouched?

Oxygen 19.1
XQuery:
-tree:linked
-ext
-update:on

Re: Special entity & breaks in custom refactoring XQuery Update operation

Posted: Wed Aug 29, 2018 8:10 am
by Radu
Hi,

We have a predefined XQuery script for converting attributes to elements (OXYGEN_INSTALL_DIR\refactoring\convert-attribute-to-element.xq), I tried to use the conversion on an XML which has both " and & but I cannot reproduce the problem (I tested with both Oxygen 19.1 and 20.1).
Would it be possible for you to send us a sample XQuery update operation (XML descriptor + Xquery + maybe sample XML document) with which we could reproduce the problem on our side? You can also send us an email to support@oxygenxml.com if you do not want to paste the script here.

Regards,
Radu

Re: Special entity & breaks in custom refactoring XQuery Update operation

Posted: Wed Aug 29, 2018 10:21 am
by dnl
Thanks. I tried the script you named, it works without problems.

Can you reproduce with the following script? Am I missing something in the serialisation options? Again, it works in the transformation scenario and only fails when called from the XML refactoring menu.

Input:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <text>A &amp; B is &quot;C&quot;</text>
  <fn typ="manuell" position="fussnote" id="fn0001">
    <kennung>X</kennung>
    <absatz>Regulation &amp; Management.</absatz>
  </fn>
</root>


XQuery Update:

Code: Select all

declare namespace saxon="http://saxon.sf.net/";
declare option saxon:output "method=xml";
declare option saxon:output "indent=no";

let $fn_all := doc(document-uri(/))/root/descendant::fn

for $fn in $fn_all

  let $this_att_typ := $fn/@typ
  let $this_att_position := $fn/@position
  let $fn_count := count($fn/preceding::fn[@position eq $this_att_position])+1
  let $kennung := <kennung>{$fn_count}</kennung>
 
  return
 
  (
  delete node $fn/kennung,
  insert node $kennung as first into $fn,
  replace value of node $this_att_typ with 'manuell'
  )


Output:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <text>A & B is "C"</text>
  <fn typ="manuell" position="fussnote" id="fn0001"><kennung>1</kennung>
   
    <absatz>Regulation & Management.</absatz>
  </fn>
</root>


Thanks for having a look.

Re: Special entity &amp; breaks in custom refactoring XQuery Update operation

Posted: Wed Aug 29, 2018 2:14 pm
by Radu
Hi,

I can reproduce the problem with your samples, we'll look into fixing this, I will update this forum thread when we do. If I find a workaround for this current behavior I will update this forum thread. in the meantime you could try to use an XSLT script instead.

Regards,
Radu

Re: Special entity &amp; breaks in custom refactoring XQuery Update operation

Posted: Wed Aug 29, 2018 3:00 pm
by Radu
Hi,

Found a workaround, replace:

Code: Select all

let $fn_all := doc(document-uri(/))/root/descendant::fn


with:

Code: Select all

let $fn_all := /root/descendant::fn


Regards,
Radu

Re: Special entity &amp; breaks in custom refactoring XQuery Update operation

Posted: Wed Aug 29, 2018 3:10 pm
by dnl
Thank you Radu, this works.

Only issue there is with this workaround there is an error from Saxon in the transformation scenario:

Programmname: Saxon-EE XQuery 9.7.0.19
Fehlerlevel: warning
Beschreibung: net.sf.saxon.tree.linked.DocumentImpl@754b7981 Updated document discarded because it was not read using doc()

I hope this can be fixed in the future so that we can use the same Xquery Update scripts in both, refactoring and transformation scenarios.

Thanks again, appreciate your quick help.