Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - xsl topological sort >Thread Next - Re: xsl topological sort Re: xsl topological sortTo: NULL Date: 5/14/2007 1:57:00 PM
Edward Wohlman wrote:
> Is it possible to use xsl to perform a topological sort such that data
> such as
>
> <Route>
> <Place>B</Place>
> <Place>D</Place>
> <Place>F</Place>
> </Route>
> <Route>
> <Place>A</Place>
> <Place>B</Place>
> <Place>C</Place>
> <Place>E</Place>
> </Route>
> <Route>
> <Place>C</Place>
> <Place>D</Place>
> <Place>E</Place>
> </Route>
> <Route>
> <Place>A</Place>
> <Place>E</Place>
> <Place>F</Place>
> </Route>
>
> can be transformed to
>
> <Route>
> <Place>A</Place>
> <Place>B</Place>
> <Place>C</Place>
> <Place>D</Place>
> <Place>E</Place>
> <Place>F</Place>
> </Route>
The simply looks like an alphabetical sort of distinct Place contents,
like this:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:strip-space elements="*"/>
<xsl:output method="xml" indent="yes"/>
<xsl:key name="distinct-place" match="Place" use="."/>
<xsl:template match="/*">
<xsl:copy>
<Route>
<xsl:apply-templates select="Route/Place[generate-id() =
generate-id(key('distinct-place', .)[1])]">
<xsl:sort select="." data-type="text"/>
</xsl:apply-templates>
</Route>
</xsl:copy>
</xsl:template>
<xsl:template match="Place">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</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 | |||
|
