Now, why I am writing this post! Because XQuery 1.0 has no support for INSERT Node function which is applicable in XQuery 3.0.
Below is what you can achieve in XQuery 3.0.
This is not possible in XQuery 1.0 or 1.1 hence I am putting my thoughts around it and presenting a utility module which I will keep on enhancing for other such functions. For now, this post is for INSERT.
Below is what I have implemented.
I have used recursion in XQuery to achieve this.
This really gets the work done. I have the below options for this utility module:
- Insert Before
- Insert After
- Insert First-Child
- Insert Last-Child
If you are looking for some additional options let me know. Hope this is helpful.
You can download the source code from here – Utility.