<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
	<xsl:key name="grp" match="value" use="attribute[@name='value']/value"/>
	<xsl:template match="/">
		<root>
			<xsl:for-each select="//property/attribute[@name='activities']">
				<xsl:for-each select="value[count(.|key('grp',attribute[@name='value']/value)[1])=1]">
					<xsl:sort select="attribute[@name='value']/value/@order"/>

					<xsl:variable name="k" select="attribute[@name='value']/value"/>

					<distance>

						<xsl:choose>
							<xsl:when test="$k">
								<xsl:attribute name="value">
									<xsl:value-of select="$k"/>
								</xsl:attribute>

								<xsl:for-each select="key('grp',$k)">
									<xsl:sort select="$k"/>
									<activity>
										<xsl:value-of select="attribute[@name='literal']/value"/>
									</activity>
								</xsl:for-each>
							</xsl:when>

							<xsl:otherwise>
								<xsl:attribute name="value">
									<xsl:text>Unspecified</xsl:text>
								</xsl:attribute>

								<xsl:for-each select="attribute[@name='literal']/value[string-length(attribute[@name='value']/value) = 0]">
									<activity>
										<xsl:value-of select="."/>
									</activity>
								</xsl:for-each>

							</xsl:otherwise>
						</xsl:choose>
					</distance>
				</xsl:for-each>
			</xsl:for-each>
		</root>
	</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2006. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="activities.xml" userelativepaths="yes" externalpreview="no" url="activities.xml" htmlbaseurl="" outputurl="" processortype="internal" useresolver="yes" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator=""/></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/><MapperBlockPosition></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
-->