Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Newbie: Sort Xml to Xml >Thread Next - Re: Newbie: Sort Xml to Xml Re: Newbie: Sort Xml to XmlTo: NULL Date: 5/19/2009 1:30:00 AM Here is a short xslt that will just sort by PileNo and copy the exact xml to the result tree. The sort is done in the first match template with the copy occurring after the sort. Also note that you will want to set the data-type on the sort or it will try to alpha sort instead. You could also transform it into a different xml document after the sorting occurs. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:template match="PileCoords"> <xsl:copy> <xsl:apply-templates> <xsl:sort data-type="number" select="PileNo"/> </xsl:apply-templates> </xsl:copy> </xsl:template> <xsl:template match="*"> <xsl:copy> <xsl:apply-templates/> </xsl:copy> </xsl:template> </xsl:stylesheet> Hope this helps. - Jeff "Dave F." <df@b...> wrote in message news:u0d3Wup1JHA.1096@T...... > Hi > > I'm just starting out with XSL so please bear with me. > > I have an XML file in the following format: > > <PileCoords> > <Pile> > <PileNo>22</PileNo> > <Eastings>57.7981568796959</Eastings> > <Northings>166.059281023945</Northings> > </Pile> > <Pile> > <PileNo>21</PileNo> > <Eastings>57.7981568796959</Eastings> > <Northings>161.461817940551</Northings> > </Pile> > <Pile> > <PileNo>194</PileNo> > <Eastings>68.6908869290537</Eastings> > <Northings>167.952353915529</Northings> > </Pile> > <Pile> > <PileNo>4</PileNo> > <Eastings>83.9813040551062</Eastings> > <Northings>167.952353915529</Northings> > </Pile> > </PileCoords> > > I would like to sort it by the PileNo element & keep it in XML format. > I've seen many examples where it's transformed to another format but very > few to keep it as XML. > > In this example: > http://www.zvon.org/xxl/XSL-Ref/Tutorials/Sorting/so5.html > The element is explicitly defined in the template. Is this essential? > It would work in this case where I know all the elements names (eg PileNo, > Eastings Northings etc) but what if they'd varied in number & names? > > Is there a way to say 'copy all the elements under Pile regardless of what > they're called'? > > I hope I've used clear terminology. > > Any help to find a solution would be greatly appreciated. > > Thanks > Dave F. > > > > > > > > | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
