title: XSLT: How to use format-number and decimal-format?
body: <p>I know such questions have been asked before but I still don't get it. </p>
  
  <p>I am using .NET for XSL transformations.</p>
  
  <p><a href="https://msdn.microsoft.com/de-de/library/ms256225(v=vs.120).aspx" rel="nofollow noreferrer">MSDN</a> describes format-number as:</p>
  
  <blockquote>
    <p>Converts numbers into strings. The conversion is the result of formatting the number specified in the first argument (number), using the format specified in the second argument (string), and applying the rules defined in the decimal format named in the third optional argument (string). If the third argument, the decimal format name, is omitted, the default decimal format is used. This function and the  element are designed to be used together. </p>
  </blockquote>
  
  <p><strong>Example</strong></p>
  
  <p>Given the following XML I want to set up a XSLT that exposes the decimals as european notaton ('.' as decimal separator and ',' as group separator) and in english (or standard notation).</p>
  
  <p>data.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;Model&gt;
    &lt;Decimal value="1.256"/&gt;
    &lt;Decimal value="19099.33345"/&gt;
  &lt;/Model&gt;
  </code></pre>
  
  <p>I use a XSLT document that declares both decimal formats and uses them in the select-statement, one time in order to output in european and one time to output in english notation:</p>
  
  <p>trafo.xslt</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
  &gt;
      &lt;xsl:decimal-format name="european" decimal-separator=',' grouping-separator='.' /&gt;
      &lt;xsl:decimal-format name="en" decimal-separator='.' grouping-separator=',' /&gt;
  
    &lt;xsl:template match="/Model"&gt;
  
        &lt;xsl:for-each select="Decimal"&gt;
          Auf european: &lt;xsl:value-of select="format-number(@value, '###.###,00', 'european')"/&gt;
          &lt;!--Auf englisch: &lt;xsl:value-of select="format-number(@value, '###.###,00', 'en')"/&gt;--&gt;
        &lt;/xsl:for-each&gt;
  
        &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>My expectation is that the transformation will output something like:</p>
  
  <pre><code>european: 1,256
  english: 1.256
  european: 19.099,33345
  english: 19,099.33345
  </code></pre>
  
  <p>But instead I get the exception also mentioned <a href="https://stackoverflow.com/questions/15095435/xslt-decimal-format-causes-exception">here</a>:</p>
  
  <blockquote>
    <p>"Format '#,###.00' cannot have zero digit symbol after digit symbol after decimal point."</p>
  </blockquote>
  
  <p>So when I need to change the format pattern for english and european notations what is the purpose of decimal-format at all?</p>
  
  <p>For completeness, here is the C# code I used for the transformation</p>
  
  <pre><code>        XDocument data = XDocument.Load("data.xml");
          XDocument xslt = XDocument.Load("trafo.xslt");
  
          XslCompiledTransform compiled = new XslCompiledTransform();
          using (var reader = xslt.CreateReader())
          {
              compiled.Load(reader);
          }
  
          // wir wollen auch Fragmente zulassen
          var writerSettings = new XmlWriterSettings { ConformanceLevel = ConformanceLevel.Auto };
          var readerSettings = new XmlReaderSettings { ConformanceLevel = ConformanceLevel.Auto };
          var stringReader = new StringReader(data.ToString());
          var details = new StringBuilder();
          using (var reader = XmlReader.Create(stringReader, readerSettings))
          {
              using (var writer = XmlWriter.Create(details, writerSettings))
              {
                  compiled.Transform(reader, writer);
              }
          }
  
          Console.WriteLine(details.ToString());
  </code></pre>