Suppose you have a TSQL query:
1 as 'Category1/@Level',
2 as 'Category2/@Level',
t.MainCat as 'Category1',
t.SubCat as 'Category2'
FOR XML PATH (''), ROOT('Taxonomy')
which generates following result:
<Taxonomy>
<Category1 Level="1">Clothing</Category1>
<Category2 Level="2">Jeans</Category2>
</Taxonomy>
The element Category1 and Category2 have unique names for the sql query to generate and convert in to xml format. That's why I used Category1 and Category2. I would like the end result to be like this:
<Taxonomy>
<Category Level="1">Clothing</Category>
<Category Level="2">Jeans</Category>
</Taxonomy>
This could be done using XML EXPLICIT like here, but since my code is much larger it becomes very cluttered and complex quite fast.
With xml.modify you can change values or attributes, but not the element itself.
Is there a way to store the first query result in a @X1 xml variable and then change the element Category1 & Category2 into Category and put it into variable @X2? Something like a search and replace used in text files, but then during the query.