<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>

	<!--
		input: <path d="M 20,20 L 200,20 100,200 Z"/>
		output: <path>
					<d>
						<move position="absolute">
							<x>20</x>
							<y>20</y>
						</move>
						<lineto position="absolute">
							<x>200</x>
							<y>20</y>
						</lineto>
						<lineto position="absolute">
							<x>100</x>
							<y>200</y>
						</lineto>
						<closepath position="absolute" />
					</d>
				</path>
	-->

	<xsl:template match="/">
		<path>
			<d>
				<xsl:call-template name="parse">
					<xsl:with-param name="path" select="normalize-space(path/@d)"/>
				</xsl:call-template>
			</d>
		</path>
	</xsl:template>

	<xsl:template name="parse">
		<xsl:param name="path"/>
		<xsl:variable name="cmd">
			<xsl:value-of select="substring-before(concat($path, ' '),' ')"/>
		</xsl:variable>

		<xsl:variable name="path2">
			<xsl:value-of select="substring-after(concat($path, ' '),' ')"/>
		</xsl:variable>

		<xsl:choose>
			<xsl:when test="$cmd = 'M'">
				<move position="absolute">
					<x>
						<xsl:value-of select="substring-before($path2, ',')"/>
					</x>
					<y>
						<xsl:value-of select="substring-after(substring-before($path2, ' '), ',')"/>
					</y>
				</move>
				<xsl:call-template name="parse">
					<xsl:with-param name="path">
						<xsl:value-of select="substring-after(concat($path2, ' '), ' ')"/>
					</xsl:with-param>
				</xsl:call-template>
			</xsl:when>

			<xsl:when test="$cmd = 'L'">
				<lineto position="absolute">
					<x>
						<xsl:value-of select="substring-before($path2, ',')"/>
					</x>
					<y>
						<xsl:value-of select="substring-after(substring-before($path2, ' '), ',')"/>
					</y>
				</lineto>

				<xsl:variable name="next">
					<xsl:value-of select="substring-after(concat($path2, ' '), ' ')"/>
				</xsl:variable>

				<!-- check for chained lineto's -->
				<xsl:variable name="lineto">
					<xsl:if test="contains(substring-before(concat($next, ' '), ' '), ',')">
						<xsl:value-of select="substring-before(concat($next, ' '), ' ')"/>
					</xsl:if>
				</xsl:variable>

				<xsl:variable name="next2">
					<xsl:choose>
						<xsl:when test="$lineto">
							<xsl:value-of select="concat('L ', $next)"/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="$next"/>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:variable>

				<xsl:call-template name="parse">
					<xsl:with-param name="path" select="$next2"/>
				</xsl:call-template>
			</xsl:when>

			<xsl:when test="$cmd = 'Z'">
				<closepath position="absolute"/>
			</xsl:when>
		</xsl:choose>
	</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2005. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="Scenario1" userelativepaths="yes" externalpreview="no" url="svg.xml" htmlbaseurl="" outputurl="" processortype="internal" useresolver="yes" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext=""/></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/><MapperBlockPosition></MapperBlockPosition><TemplateContext></TemplateContext></MapperMetaTag>
</metaInformation>
-->