Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: xsl topological sort [Thread Next] Re: xsl topological sortTo: NULL Date: 5/14/2007 1:26:00 PM
"Martin Honnen" <mahotrash@y...> wrote in message
news:#CtxM8hlHHA.4772@T......
> 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/
Thanks, but I was using A-B-C as a simplified example of what I need.
The actual data I will be operating on will not be sort able so easily.
I've made a bit of a start at working out the dependencies for each place
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<xsl:key name="places" match="//Route/Place" use="."/>
<xsl:template match="TopoTest">
<table border="2">
<tr><th>place</th><th>depends on</th></tr>
<xsl:for-each select="Route/Place[generate-id() =
generate-id(key('places',.)[1])]">
<tr>
<td><xsl:value-of select="."/></td>
<td>
<xsl:for-each select="key('places',.)">
<xsl:for-each select="preceding-sibling::node()">
<xsl:value-of select="."/>
</xsl:for-each>
</xsl:for-each>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:transform>
but even that is not giving me quite what I wanted quite yet.
Looks like I need to learn a lot more about this stuff
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
