﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Programming / XML  / normalizing XML data via transformation / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sat, 25 May 2013 04:40:39 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: normalizing XML data via transformation</title><link>http://www.sqlservercentral.com/Forums/Topic1370122-21-1.aspx</link><description>Personally I would use XQuery to do the transformation. I save xslt for the hardest of transformations, but to be honest, I have been able to do most things in XQuery. If the data is already stored in your sql tables, this makes it a bit easier as you can use tsql and not have to worry about creating a clr or another app/ssis to read the data out, do the transformation and save it back.for example, I quickly created the following based on your example you documented to do the transformation using xquery:[code="sql"]DECLARE @xml XMLSET @xml = '&amp;lt;Appointments&amp;gt;&amp;lt;Appointment id = "1"&amp;gt;&amp;lt;person&amp;gt;&amp;lt;Name&amp;gt;John Doe&amp;lt;/Name&amp;gt;&amp;lt;/person&amp;gt;&amp;lt;location&amp;gt;&amp;lt;name&amp;gt;Main&amp;lt;/name&amp;gt;&amp;lt;address&amp;gt;456 Oak St.&amp;lt;/address&amp;gt;&amp;lt;State&amp;gt;NY&amp;lt;/State&amp;gt;&amp;lt;/location&amp;gt;&amp;lt;/Appointment&amp;gt;&amp;lt;Appointment id = "2"&amp;gt;&amp;lt;person&amp;gt;&amp;lt;Name&amp;gt;Jane Doe&amp;lt;/Name&amp;gt;&amp;lt;/person&amp;gt;&amp;lt;location&amp;gt;&amp;lt;name&amp;gt;Main&amp;lt;/name&amp;gt;&amp;lt;address&amp;gt;456 Oak St.&amp;lt;/address&amp;gt;&amp;lt;State&amp;gt;NY&amp;lt;/State&amp;gt;&amp;lt;/location&amp;gt;&amp;lt;/Appointment&amp;gt;&amp;lt;Appointment id = "3"&amp;gt;&amp;lt;person&amp;gt;&amp;lt;Name&amp;gt;george Doe&amp;lt;/Name&amp;gt;&amp;lt;/person&amp;gt;&amp;lt;location&amp;gt;&amp;lt;name&amp;gt;Satellite&amp;lt;/name&amp;gt;&amp;lt;address&amp;gt;123 Main St.&amp;lt;/address&amp;gt;&amp;lt;State&amp;gt;NY&amp;lt;/State&amp;gt;&amp;lt;/location&amp;gt;&amp;lt;/Appointment&amp;gt;&amp;lt;/Appointments&amp;gt;'SELECT @xml.query('for $x in /Appointments return&amp;lt;Appointments&amp;gt;	{		for $y in distinct-values($x/Appointment/location/name/text())		return			($x/Appointment/location[name = $y])[1]				}	{		for $y in $x/Appointment		return			&amp;lt;Appointment id="{$y/@id}"&amp;gt;				{$y/person}				&amp;lt;location name="{$y/location/name/text()}"/&amp;gt;			&amp;lt;/Appointment&amp;gt;	}&amp;lt;/Appointments&amp;gt;')[/code]You can see the main guts of the code is quite small and remodels the xml as you require.[url]http://msdn.microsoft.com/en-us/library/ms189075.aspx[/url]</description><pubDate>Tue, 09 Oct 2012 01:29:18 GMT</pubDate><dc:creator>arthurolcot</dc:creator></item><item><title>normalizing XML data via transformation</title><link>http://www.sqlservercentral.com/Forums/Topic1370122-21-1.aspx</link><description>I'm a newbie with XML, but i was wondering if somebody could get me started down the path of how to normalize out some XML data.  I *think* if I can do this via XSLT, but not sure of what to research.  Basically I have nodes that across the document have repeating groups, and I'm curious if I can normalize them into a common node.  I'm hoping that I can use this as part of an SSIS package.  I would have the first XSD, and the second XSD, what I don't have is the "transalation" peice.For example:...&amp;lt;Appointments&amp;gt;   &amp;lt;Appointment id = "1"&amp;gt;      &amp;lt;person&amp;gt;         &amp;lt;Name&amp;gt;John Doe&amp;lt;/Name      &amp;lt;/person&amp;gt;      &amp;lt;location&amp;gt;         &amp;lt;name&amp;gt;Main&amp;lt;/name&amp;gt;         &amp;lt;address&amp;gt;456 Oak St.&amp;lt;/address&amp;gt;         &amp;lt;State&amp;gt;NY&amp;lt;/State&amp;gt;      &amp;lt;/location&amp;gt;&amp;lt;/Appointment&amp;gt;   &amp;lt;Appointment id = "2"&amp;gt;      &amp;lt;person&amp;gt;         &amp;lt;Name&amp;gt;Jane Doe&amp;lt;/Name      &amp;lt;/person&amp;gt;      &amp;lt;location&amp;gt;         &amp;lt;name&amp;gt;Main&amp;lt;/name&amp;gt;         &amp;lt;address&amp;gt;456 Oak St.&amp;lt;/address&amp;gt;         &amp;lt;State&amp;gt;NY&amp;lt;/State&amp;gt;      &amp;lt;/location&amp;gt;&amp;lt;/Appointment&amp;gt;   &amp;lt;Appointment id = "3"&amp;gt;      &amp;lt;person&amp;gt;         &amp;lt;Name&amp;gt;george Doe&amp;lt;/Name      &amp;lt;/person&amp;gt;      &amp;lt;location&amp;gt;         &amp;lt;name&amp;gt;Satellite&amp;lt;/name&amp;gt;         &amp;lt;address&amp;gt;123 Main St.&amp;lt;/address&amp;gt;         &amp;lt;State&amp;gt;NY&amp;lt;/State&amp;gt;      &amp;lt;/location&amp;gt;&amp;lt;/Appointment&amp;gt;&amp;lt;/Appointments&amp;gt;...How do I get that to be something more like...&amp;lt;Appointments&amp;gt;      &amp;lt;location&amp;gt;         &amp;lt;name&amp;gt;Main&amp;lt;/name&amp;gt;         &amp;lt;address&amp;gt;456 Oak St.&amp;lt;/address&amp;gt;         &amp;lt;State&amp;gt;NY&amp;lt;/State&amp;gt;      &amp;lt;/location&amp;gt;      &amp;lt;location&amp;gt;         &amp;lt;name&amp;gt;Satellite&amp;lt;/name&amp;gt;         &amp;lt;address&amp;gt;123 Main St.&amp;lt;/address&amp;gt;         &amp;lt;State&amp;gt;NY&amp;lt;/State&amp;gt;      &amp;lt;/location&amp;gt;    &amp;lt;Appointment id = "3"&amp;gt;      &amp;lt;person&amp;gt;         &amp;lt;Name&amp;gt;george Doe&amp;lt;/Name      &amp;lt;/person&amp;gt;      &amp;lt;location name = "Satellite"/&amp;gt;   &amp;lt;/Appointment&amp;gt;    &amp;lt;Appointment id = "2"&amp;gt;      &amp;lt;person&amp;gt;         &amp;lt;Name&amp;gt;Jane Doe&amp;lt;/Name      &amp;lt;/person&amp;gt;      &amp;lt;location name ="Main"/&amp;gt;   &amp;lt;/Appointment&amp;gt;    &amp;lt;Appointment id = "1"&amp;gt;      &amp;lt;person&amp;gt;         &amp;lt;Name&amp;gt;John Doe&amp;lt;/Name      &amp;lt;/person&amp;gt;      &amp;lt;location name ="Main"/&amp;gt;   &amp;lt;/Appointment&amp;gt;&amp;lt;/Appointments&amp;gt;...Or something like that.   I'm not that concerned with element v attribute, i'm more interested in how would I do the "normalization" peice.  Right now being a DBA, i'm more inclined to load it to a staging database and do the "translation" via T-SQL, but I'm going to attempt to broaden my mind (scary).Thanks in advance,Sean</description><pubDate>Mon, 08 Oct 2012 19:00:46 GMT</pubDate><dc:creator>sean hawkes</dc:creator></item></channel></rss>