Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: xsl topological sort

From: "Edward Wohlman" <edward@--------------.--->
To: 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 



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent