Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Help sorting xml to xml [Thread Next] Re: Help sorting xml to xmlTo: NULL Date: 10/6/2009 1:14:00 PM derekmw wrote: > <a> > <b> > <c type="period"> > <key> > <d name="date">2006-09-12 00:00:00.0</d> > </key> > ...(many other elements, many which have nested elements 6-7 levels > deep) > </c> > <c type="period"> > <key> > <d name="date">2006-09-15 00:00:00.0</d> > </key> > ...(many other elements, many which have nested elements 6-7 levels > deep) > </c> > </b> > </a> > > From what I read/understood, with xsl, you have to specify all the > fields you want to copy over to the new xml transformation? If so, > that's just not an option as there are so many other elements within > the 'c' elements I want to sort by. > > What I need to do is find a quick way to sort the 'c' elements by the > 'd' element value (date). Any suggestions/direction would be > appreciated! With XSLT 1.0 you can put xsl:sort elements as children of the xsl:for-each or xsl:apply-templates elements. What you do then is up to you thus if you want to sort and then make a deep copy that is certainly possible e.g. <xsl:template match="b"> <xsl:copy> <xsl:for-each select="c"> <xsl:sort select="key/d[@name = 'date']"/> <xsl:copy-of select="."/> </xsl:for-each> </xsl:copy> </xsl:template> So the above is a template for 'b' elements that makes a shallow copy of the 'b' element and then processes the 'c' children, sorted by the text value of the "key/d[@name = 'date']" grandchild element and then simply makes a deep copy. -- Martin Honnen --- MVP XML http://msmvps.com/blogs/martin_honnen/ | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
