<?xml version="1.0" encoding="UTF-8"?>
<!--
    XSLT 2.0 stylesheet for length reducing of Inkscape generated SVG coordinates (attribute values)
    Version 1.0 (2011-05-07) by Dr. Thomas Meinike - http://datenverdrahten.de/xslt2/svg_reduce.xsl
    Using with Saxon-HE 9.3 (http://saxon.sourceforge.net/):
    java -jar X:\path_to_Saxon9\saxon9he.jar -s:source.svg -xsl:svg_reduce.xsl -o:destination.svg
-->
<xsl:stylesheet version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:fn="http://www.w3.org/2005/xpath-functions"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:svg="http://www.w3.org/2000/svg"
  xmlns:xlink="http://www.w3.org/1999/xlink"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:cc="http://web.resource.org/cc/"
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
  xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
  xpath-default-namespace="http://www.w3.org/2000/svg"
  exclude-result-prefixes="fn xs">


  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>


  <!-- max. fraction digits in destination.svg: -->
  <xsl:variable name="d" select="2"/>


  <xsl:template match="element()">
    <xsl:copy>
      <xsl:apply-templates select="attribute(), node()"/>
    </xsl:copy>
  </xsl:template>


  <xsl:template match="text() | comment() | processing-instruction()">
    <xsl:copy/>
  </xsl:template>


  <xsl:template match="attribute()">
    <xsl:attribute name="{name()}">
      <xsl:analyze-string select="." regex="(\d+)(\.)(\d+)">
        <xsl:matching-substring>
          <xsl:variable name="val" select="fn:concat(regex-group(1), regex-group(2), regex-group(3))"/>
          <xsl:value-of select="fn:round-half-to-even(fn:number($val), $d)"/>
        </xsl:matching-substring>
        <xsl:non-matching-substring>
          <xsl:value-of select="."/>
        </xsl:non-matching-substring>
       </xsl:analyze-string>
    </xsl:attribute>
  </xsl:template>

</xsl:stylesheet>
