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 XmlTo: NULL Date: 5/17/2009 12:21:00 PM Dave F. wrote:
> <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.
Here is a sample stylesheet that processes the Pile child elements of
the PileCoords elements in the order given by the PileNo element and
otherwise copies everything:
<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:template match="PileCoords">
<xsl:copy>
<xsl:apply-templates select="Pile">
<xsl:sort select="PileNo" data-type="number"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
--
Martin Honnen --- MVP XML
http://msmvps.com/blogs/martin_honnen/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
