<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
>

<xsl:output method="xml" encoding="UTF-8" omit-xml-declaration="yes" indent="yes" />

<xsl:template match="svg">
  <xsl:element name="svg">
    <xsl:apply-templates/>
 </xsl:element>
</xsl:template>

<xsl:template match="path">
 <xsl:variable name="path_d" select="@d"/>


	<xsl:call-template name="DoParse">
		<xsl:with-param name="path" select="normalize-space($path_d)"/>
	</xsl:call-template>
</xsl:template>

<xsl:template name="DoParse">
	<xsl:param name="path"/>
	  <xsl:variable name="temp" select="normalize-space(translate($path,'mMLlVvHhCcSsTtQqAaZz ,-.0123456789','mMLlVvHhCcSsTtQqAaZz              '))"/>
	  <xsl:variable name="commands" select="translate($temp,'mMLlVvHhCcSsTtQqAaZz ','mMLlVvHhCcSsTtQqAaZz')"/>
	  <thecommands><xsl:value-of select="$commands"/></thecommands>
	  <xsl:call-template name="command_separetor">
		<xsl:with-param name="path1" select="normalize-space($path)"/>
		<xsl:with-param name="path2" select="''"/>
		<xsl:with-param name="commands" select="$commands"/>
		<xsl:with-param name="firstcom" select="substring($commands,1,1)"/>
	  </xsl:call-template>
</xsl:template>


<!--This is the template that removes any commas and replace them by comma-->
<xsl:template name="command_separetor">
	<xsl:param name="path1"/>
	<xsl:param name="path2"/>
	<xsl:param name="commands"/>
	<xsl:param name="firstcom"/>

	<xsl:choose>  	    
     <xsl:when test="contains($path1, $firstcom)">
	   <xsl:variable name="cmd1">
		 <xsl:value-of select="concat(' ',substring-before($path1,$firstcom), ' ')"/>
       </xsl:variable>
 	   <xsl:variable name="cmd2">
	     <xsl:value-of select="concat(substring-after($path1, $firstcom),' ')"/>
	   </xsl:variable>
	   <xsl:call-template name="command_separetor">
		<xsl:with-param name="path1" select="$cmd2"/>
		<xsl:with-param name="path2" select="concat($path2,$cmd1,$firstcom)"/>
		<xsl:with-param name="commands" select="$commands"/>
		<xsl:with-param name="firstcom" select="$firstcom"/>
 	   </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
      <xsl:choose>
	   <xsl:when test="number(string-length($commands)) &gt; 0">
  		<xsl:call-template name="nextcommand">
		<xsl:with-param name="path1" select="concat($path2,$path1)"/>
		<xsl:with-param name="path2" select="''"/>
		<xsl:with-param name="commands" select="$commands"/>
		<xsl:with-param name="firstcom" select="$firstcom"/>
 	   </xsl:call-template>
	  </xsl:when>
  	  <xsl:otherwise>
	   <xsl:element name="path">
	    <xsl:attribute name="d">
		 <xsl:value-of select="normalize-space(concat($path2,$path1))"/>
        </xsl:attribute>
	   </xsl:element>
      </xsl:otherwise>
     </xsl:choose>
   </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template name="nextcommand">
  <xsl:param name="path1"/>
  <xsl:param name="path2"/>
  <xsl:param name="commands"/>
  <xsl:param name="firstcom"/>
    

   <xsl:variable name="nextcom">
    <xsl:value-of select="substring($commands,2,1)"/>
   </xsl:variable>
   <xsl:variable name="newlist">
    <xsl:value-of select="substring($commands,3,string-length($commands) - 2)"/> 
   </xsl:variable>

  <xsl:choose>
  <xsl:when test="($nextcom = $firstcom) and ($nextcom &gt; 0)">
   <xsl:call-template name="nextcommand">
   <xsl:with-param name="path1" select="$path1"/>
   <xsl:with-param name="path2" select="''"/>
   <xsl:with-param name="commands" select="$newlist"/>
   <xsl:with-param name="firstcom" select="$nextcom"/>
   </xsl:call-template>
  </xsl:when>
  <xsl:otherwise>
   <xsl:call-template name="command_separetor">
   <xsl:with-param name="path1" select="$path1"/>
   <xsl:with-param name="path2" select="''"/>
   <xsl:with-param name="commands" select="$newlist"/>
  <xsl:with-param name="firstcom" select="$nextcom"/>
 </xsl:call-template>
</xsl:otherwise>
</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="..\tests\w3logo.svg" htmlbaseurl="" outputurl="" processortype="internal" 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></MapperMetaTag>
</metaInformation>
-->