Contents tagged with Xml Functions

  • Retrieving the next or previous element node value in an Xml blob using XQuery

    It’s been a little while since I wrote a blog post on my favourite subject but this is from a thread on the SSC Xml forum that I was helping out on a couple of weeks ago. I’ve been a bit busy lately with a big project at work, revising/taking exam 70-461 and getting ready for the birth of my second child! But this thread seemed too good a subject for me to miss quickly get a post out showing how I might approach this particular problem.

    Sometimes we are given a pretty poorly …

  • Using XQuery to remove duplicate values or duplicate nodes from an xml instance

    Sometimes we need to retrieve a list distinct values from within an xml instance or even distinct nodes and this is relatively straight forward using XQuery. It gets a bit more complicated if you have attributes in the xml, but it is still possible to retrieve unique xml nodes. On the flip side, it is also possible to only return xml nodes that are duplicated in the xml instance. All the examples can be downloaded here

    Retrieving Distinct Values

    Getting a list of distinct atomic values from a …

  • Using XQuery to transform multiple xml nodes to a single xml node with comma separated string value

    Not another comma separated string blog post I hear you say! I know that this topic has probably been done to death but I hope that this is a little different as it is about creating a single xml node containing a comma separated string from the values of multiple other xml nodes all within an XQuery expression.

    Recently I’ve been working on some xml migrations using XQuery and one of the many types of transformations that I had to do was to take a number of identically named xml nodes …

  • Retrieving position() value of node by using XQuery alone

    You can only use the position() function within an xquery predicate and can't use it to return the position value of the node itself, which is a shame, but a couple of good workarounds have been published. However I had a requirement (don't ask why!) to return the position() of the node as a value within the xml itself.

    My requirement was to return an existing xml structure but to also include the position of a particular node as an additional attribute of that node. My other goal was to keep …

  • FOR XML PATH using node tests in column aliases

    I've used SQL to generate countless blobs of xml over the years and one feature that I have come to rely heavily upon is the ability to easily build complex xml structures by using column aliases in conjunction with the FOR XML PATH clause in your query. Not only do they allow for speedy creation, they also make the query very readable and it doesn't take long to be able to visualize the xml structure just by looking at the query itself. In conjunction with this, there are a number of node …