Delete all child nodes except last node

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Delete all child nodes except last node

kanchan
Hi All,

I have one xml like below and I want to delete all the elements except last.

<Specific-price>
<group>
<item>
<value>2000</value>
<desc>Test 1</desc>
</item>
<max>10</max>
</group>
<group>
<item>
<value>4000</value>
<desc>Test 2</desc>
</item>
<max>20</max>
</group>
<group>
<item>
<value></value>
<desc></desc>
</item>
<max></max>
</group>
</Specific-price>


So, I thought first to try delete all and then insert one node
Below is I tried but not working
<xforms:delete nodeset="../Specific-price/group" />

However, if I tried
<xforms:delete nodeset="../Specific-price" />
It deletes the complete node Specific-price. But I want to delete all children of specific-price.


Could you please help me?
Reply | Threaded
Open this post in threaded view
|

Re: Delete all child nodes except last node

Alessandro  Vernet
Administrator
Hi,

The following should do it:

    <xf:delete ref="/Specific-price/group[exists(following-sibling::group)]"/>

In essence, you're saying: delete all the instances of a "group" for which we can find another "group" after that. You'll let us know if this works for you,

Alex

On Sun, Jan 8, 2017 at 9:43 PM kanchan <[hidden email]> wrote:
Hi All,

I have one xml like below and I want to delete all the elements except last.

<Specific-price>
<group>
<item>
<value>2000</value>
<desc>Test 1</desc>
</item>
<max>10</max>
</group>
<group>
<item>
<value>4000</value>
<desc>Test 2</desc>
</item>
<max>20</max>
</group>
<group>
<item>
<value></value>
<desc></desc>
</item>
<max></max>
</group>
</Specific-price>


So, I thought first to try delete all and then insert one node
Below is I tried but not working
<xforms:delete nodeset="../Specific-price/group" />

However, if I tried
<xforms:delete nodeset="../Specific-price" />
It deletes the complete node Specific-price. But I want to delete all
children of specific-price.


Could you please help me?


--
View this message in context: http://discuss.orbeon.com/Delete-all-child-nodes-except-last-node-tp4662097.html
Sent from the Orbeon Forms community mailing list mailing list archive at Nabble.com.

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: Delete all child nodes except last node

kanchan
Hi Alex,

I tried solution given by you. However, only one node is getting deleted.
Result is
<Specific-price>
<group>
<item>
<value>4000</value>
<desc>Test 2</desc>
</item>
<max>20</max>
</group>
<group>
<item>
<value></value>
<desc></desc>
</item>
<max></max>
</group>
</Specific-price>

I also tried below but the same result/
<xforms:delete nodeset="../Specific-price/group[position()!=last()]" />

I want to delete all children except last. Please help me.
Reply | Threaded
Open this post in threaded view
|

Re: Delete all child nodes except last node

kanchan
In reply to this post by Alessandro Vernet
Below is the error, I got

XForms error: Missing mandatory nodeset binding for element: xforms:delete

using this solution
<xforms:delete ref="/Specific-price/group[exists(following-sibling::group)]"/>
Reply | Threaded
Open this post in threaded view
|

Re: Delete all child nodes except last node

Alessandro  Vernet
Administrator
The version of Orbeon Forms you're using might not support the "new" `ref` attribute yet. Could you try the above with `nodeset` instead of `ref`?

Alex

On Sun, Jan 8, 2017 at 11:31 PM kanchan <[hidden email]> wrote:
Below is the error, I got

XForms error: Missing mandatory nodeset binding for element: xforms:delete

using this solution
<xforms:delete
ref="/Specific-price/group[exists(following-sibling::group)]"/>

--
View this message in context: http://discuss.orbeon.com/Delete-all-child-nodes-except-last-node-tp4662097p4662100.html
Sent from the Orbeon Forms community mailing list mailing list archive at Nabble.com.

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].

--
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: Delete all child nodes except last node

kanchan
This post was updated on .
Hi Alex,
Thanks.

I tried this

<xforms:delete context="../Specific-price" while="group"  nodeset="group"/> 
This deletes all the group elements.

I want delete all except last one.

So, I tried above first. This deletes all group elements. Now I am trying to insert one element as follows

<xforms:insert at="1" position="before" nodeset="../Specific-price/group" />
This is not inserting an element.

Could you please help?
Reply | Threaded
Open this post in threaded view
|

Re: Delete all child nodes except last node

Alessandro  Vernet
Administrator
You can try this stand-alone example: view.xhtml, which in Orbeon Forms 2016.3 gives the following. Again, if you're using a very old version of Orbeon Forms, you might have to replace the `ref` by `nodeset`. I hope this helps.



Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet