Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Help needed with transform [Thread Next] Re: Help needed with transformTo: NULL Date: 12/4/2007 2:09:00 PM chris fellows wrote: > Can someone help me out as to how I can transform the following XML... Here is an XSLT 1.0 solution: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:key name="by-id" match="Row" use="MyID"/> <xsl:template match="RecordsetData"> <Data> <xsl:apply-templates select="Row[generate-id() = generate-id(key('by-id', MyID)[1])]"/> </Data> </xsl:template> <xsl:template match="Row"> <MyData> <xsl:copy-of select="MyId"/> <Values> <xsl:copy-of select="key('by-id', MyID)/Value"/> </Values> </MyData> </xsl:template> </xsl:stylesheet> And here is an equivalent XSLT 2.0 stylesheet: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output method="xml" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="RecordsetData"> <Data> <xsl:for-each-group select="Row" group-by="MyID"> <MyData> <xsl:copy-of select="MyID"/> <Values> <xsl:copy-of select="current-group()/Value"/> </Values> </MyData> </xsl:for-each-group> </Data> </xsl:template> </xsl:stylesheet> -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/ | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
