Note that there are some explanatory texts on larger screens.

plurals
  1. POXQuery not inserting child node
    text
    copied!<p>Below is the XML structure. Its a specimen of my original structure, not the exact.</p> <pre><code>&lt;Docs&gt; &lt;Doc&gt; &lt;Para&gt; &lt;P n="1"&gt;&lt;B&gt;Constants : T&lt;/B&gt;he value of pi is 3.14&lt;/P&gt; &lt;P n="2"&gt;pi is a geometric term.&lt;/P&gt; &lt;/Para&gt; &lt;/Doc&gt; &lt;Doc&gt; &lt;Para&gt; &lt;P n="1"&gt;&lt;B&gt;Constants : T&lt;/B&gt;he value of g is 9.81 m/sqr of sec&lt;/P&gt; &lt;P n="2"&gt;g is a acceleration due to gravity.&lt;/P&gt; &lt;/Para&gt; &lt;/Doc&gt; &lt;Doc&gt; &lt;Para&gt; &lt;P n="1"&gt;&lt;B&gt;Constants : T&lt;/B&gt;he value of c is 3.00 x 10 power 8 m/sec&lt;/P&gt; &lt;P n="2"&gt;c is a speed of light in vacuum.&lt;/P&gt; &lt;/Para&gt; &lt;/Doc&gt; &lt;/Docs&gt; </code></pre> <p>I have generated XML files programmatically. The <code>B</code> node has data <code>Constant : T</code>, where as it should be only <code>Constants :</code>. I have written an XQuery to do the necessary changes, but its not working as expected.</p> <p>below is the XQuery - Version 1</p> <pre><code>for $x in doc('doc1')//Doc where $x/Para/P[@n="1"]/B/text()="Constants : T" return let $p := $x/Para/P[@n="1"] let $pText := concat("T", $p/text()) let $tag := &lt;P n="1"&gt;{$pText}&lt;/P&gt; return ( delete node $p, insert node $tag as first into $x/Para, insert node &lt;B&gt;Constants :&lt;/B&gt; as first into $x/Para/P[@n="1"] ) </code></pre> <p>Version - 2 (Smaller, sweeter but not working !!!)</p> <pre><code>let $b := &lt;B&gt; Constants :&lt;/B&gt; for $x in doc('doc1')//Doc/Para[P[@n="1"]/B/text()="Constants : T"]/P[@n="1"] return ( replace value of node $x with concat("T", $x/text()), insert node $b/node() as first into $x ) </code></pre> <p>Neither query is inserting <code>&lt;B&gt;Constants : &lt;/B&gt;</code>. Can anybody help me on this?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload