| Merging Rowset in XML document
|
sotu

msg:4476561 | 11:05 pm on Jul 17, 2012 (gmt 0) | I have follwoing XML with me with multiple Rowset in it. I want to merge all Rowset into one. SO can you please help how would I do that using XSLT or with any other method? Current XML:
<?xml version="1.0" encoding="utf-8"?> <Rowsets DateCreated="2012-07-17T11:57:07" EndDate="2012-07-17T11:57:07" StartDate="2012-07-17T10:57:07" Version="12.0.12 Build(9)"> <Rowset> <Columns> <Column Description="Name" MaxRange="1" MinRange="0" Name="Name" SQLDataType="12" SourceColumn="Name"/> <Column Description="City" MaxRange="1" MinRange="0" Name="City" SQLDataType="4" SourceColumn="City"/> <Column Description="Phone" MaxRange="1" MinRange="0" Name="Phone" SQLDataType="12" SourceColumn="Phone"/> </Columns> <Row> <Name>Philip</Name> <City>London</City> <Phone>123</Phone> </Row> <Row> <Name>Derek</Name> <City>Seattle</City> <Phone>500</Phone> </Row> <Row> <Name>Bruke</Name> <City>LosAngeles</City> <Phone>600</Phone> </Row> </Rowset> <Rowset> <Columns> <Column Description="Name" MaxRange="1" MinRange="0" Name="Name" SQLDataType="12" SourceColumn="Name"/> <Column Description="City" MaxRange="1" MinRange="0" Name="City" SQLDataType="4" SourceColumn="City"/> <Column Description="Phone" MaxRange="1" MinRange="0" Name="Phone" SQLDataType="12" SourceColumn="Phone"/> </Columns> <Row> <Name>Yang</Name> <City>SFO</City> <Phone>1233</Phone> </Row> <Row> <Name>Cristina</Name> <City>SanJose</City> <Phone>890</Phone> </Row> </Rowset> <Rowset> <Columns> <Column Description="Name" MaxRange="1" MinRange="0" Name="Name" SQLDataType="12" SourceColumn="Name"/> <Column Description="City" MaxRange="1" MinRange="0" Name="City" SQLDataType="4" SourceColumn="City"/> <Column Description="Phone" MaxRange="1" MinRange="0" Name="Phone" SQLDataType="12" SourceColumn="Phone"/> </Columns> <Row> <Name>Meredith</Name> <City>Sunnyvale</City> <Phone>788</Phone> </Row> <Row> <Name>Grey</Name> <City>MountainView</City> <Phone>456</Phone> </Row> <Row> <Name>Torrence</Name> <City>SAntaClara</City> <Phone>432</Phone> </Row> </Rowset> </Rowsets>
Output XML that is Needed:
<?xml version="1.0" encoding="utf-8"?> <Rowsets DateCreated="2012-07-17T11:57:07" EndDate="2012-07-17T11:57:07" StartDate="2012-07-17T10:57:07" Version="12.0.12 Build(9)"> <Rowset> <Row> <Name>Philip</Name> <City>London</City> <Phone>123</Phone> </Row> <Row> <Name>Derek</Name> <City>Seattle</City> <Phone>500</Phone> </Row> <Row> <Name>Bruke</Name> <City>LosAngeles</City> <Phone>600</Phone> </Row> <Row> <Name>Yang</Name> <City>SFO</City> <Phone>1233</Phone> </Row> <Row> <Name>Cristina</Name> <City>SanJose</City> <Phone>890</Phone> </Row> <Row> <Name>Meredith</Name> <City>Sunnyvale</City> <Phone>788</Phone> </Row> <Row> <Name>Grey</Name> <City>MountainView</City> <Phone>456</Phone> </Row> <Row> <Name>Torrence</Name> <City>SAntaClara</City> <Phone>432</Phone> </Row> </Rowset> </Rowsets>
So can you guys plz help me how can I achieve this? Thanks !
|
Dijkgraaf

msg:4476952 | 1:24 am on Jul 19, 2012 (gmt 0) | XSLT Transform <?xml version="1.0" encoding="UTF-16"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl version="1.0"> <xsl:output omit-xml-declaration="yes" method="xml" version="1.0" /> <xsl:template match="/"> <xsl:apply-templates select="/Rowsets" /> </xsl:template> <xsl:template match="/Rowsets"> <Rowsets> <xsl:attribute name="DateCreated"> <xsl:value-of select="@DateCreated" /> </xsl:attribute> <xsl:attribute name="EndDate"> <xsl:value-of select="@EndDate" /> </xsl:attribute> <xsl:attribute name="StartDate"> <xsl:value-of select="@StartDate" /> </xsl:attribute> <xsl:attribute name="Version"> <xsl:value-of select="@Version" /> </xsl:attribute> <Rowset> <xsl:for-each select="Rowset"> <xsl:for-each select="Row"> <Row> <Name> <xsl:value-of select="Name/text()" /> </Name> <City> <xsl:value-of select="City/text()" /> </City> <Phone> <xsl:value-of select="Phone/text()" /> </Phone> </Row> </xsl:for-each> </xsl:for-each> </Rowset> </Rowsets> </xsl:template> </xsl:stylesheet>
|
|
|