To format all the Decimal fields to European Amount formatting

Hi all,

I have an XML which has Decimal field which need to formatted to European Currency format.

<?xml version="1.0" encoding="UTF-16"?>
-<Envelope>
 -<Body>
  -<getPriceRecommendationResponse>
   -<status>
     <statusCode>Success</statusCode>
    </status>
   -<priceRecommendation>
     <tssArticleNumber>Item Number1234</tssArticleNumber>
     <compoundCode>N123</compoundCode>
     <compoundGroupCodeBucket>A</compoundGroupCodeBucket>
     <compoundCodeBucket>N123 & others</compoundCodeBucket>
     <qualityIndexCode>-</qualityIndexCode>
     <qualityIndexBucket>Std Quality</qualityIndexBucket>
     <weight>66.0341</weight>
     <weightGroupBucket>BT 123.1234 and 12345.1234</weightGroupBucket>
     <weightIsValidBucket>YES</weightIsValidBucket>
     <subGroupCode>PT</subGroupCode>
     <subGroupCodeBucket>7:B03</subGroupCodeBucket>
     <stockDistinction>MTS</stockDistinction>
     <productIdBucket>PT0401450-T46N</productIdBucket>
     <referencePrice>42.076</referencePrice>
     <averageQuantity>9</averageQuantity>
     <quantityAdjustments>0.96</quantityAdjustments>
     <highDV>2.123789</highDV>
     <averageDV>1.25141</averageDV>
     <lowDV>0.79983</lowDV>
     <additionalAdjustmentsTotal>1</additionalAdjustmentsTotal>
     <highPrice>19876.9124796544</highPrice>
     <averagePrice>12345.5481540736</averagePrice>
     <lowPrice>123344567.3075011968</lowPrice>
   </priceRecommendation>
  </getPriceRecommendationResponse>
 </Body>
</Envelope>

Please help me guys i have other Xslt which i used, which will help you to know the format i am looking for

//this has been taken from a Microsoft knowledgebase aricle and strips out the
//namespaces from an XML message using a style sheet
XslTransform :=  XslTransform.XslTransform;
XMLStyleSheet := XMLStyleSheet.XmlDocument;
XMLStyleSheet.InnerXml(
'<?xml version="1.0" encoding="UTF-8"?>'+
'<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:msxml="urn:schemas-microsoft-com:xslt">'+
'<xsl:output method="xml" omit-xml-declaration="yes" version="1.0" encoding="UTF-8" indent="yes"/>' +
'<xsl:template match="@*|node()">'+
'<xsl:copy>'+
'<xsl:apply-templates select="@*|node()"/>'+
'</xsl:copy>'+
'</xsl:template>'+
'<xsl:template match="'+OldNode+'">'+
'<xsl:variable name="oldNode" select="'+OldNode+'"/>' +
'<xsl:variable name="newNodeXml">' +
'<xsl:element name="'+NewNode+'">' +
'<xsl:copy-of select="$oldNode/@*|node()"/>' +
'<xsl:copy-of select="$oldNode/child::*"/>' +
'<xsl:copy-of select="$oldNode/@*"/>' +
'</xsl:element>' +
'</xsl:variable>' +
'<xsl:copy-of select="msxml:node-set($newNodeXml)"/>' +
'</xsl:template>' +
'</xsl:stylesheet>'
);
XslTransform.Load(XMLStyleSheet);
writer := writer.StringWriter();
XslTransform.Transform(Source, nullXsltArgumentList, writer);
Destination := Destination.XmlDocument;
Destination.InnerXml(writer.ToString());

//'<xsl:with-param name="text" select="." />' +

Any Help? :frowning:

Define European format first

Thank you for your response. I hope i can make the things more clear to you. The European format is “,” for Decimal separator and “.” for Digit Grouping. Whereas US have the reverse. For example 1,000.156 in US and 1.000,156 for Europe. The problem here is i need to use it multiple times for the Fields. I want an XSLT which change the format for all the decimal fields at once. I hope you got my point

That’s what I thought. But that’s not true for all European coutries. UK is Europe and uses dot for decimals and commas for thousands.

I assume that you want something like this

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:decimal-format name="euro" decimal-separator="," grouping-separator="."/>
  <xsl:template match="/">
    <xsl:value-of select="format-number(26825.8, '#.###,00', 'euro')"/>
  </xsl:template>
</xsl:stylesheet>

Now, this is generic code, I haven’t applied it to your existing XSL but you get the idea

Thanks Molona,

I have created an XSLT as follows

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:msxml="urn:schemas-microsoft-com:xslt">
<xsl:output method="xml" omit-xml-declaration="yes" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>
<xsl:decimal-format name="eu" decimal-separator=',' grouping-separator='.' />
<xsl:template match="*[not(*) and number()=number()]">
    <xsl:copy>
        <xsl:value-of select="format-number(., '#.##0,##########', 'eu')" />
    </xsl:copy> 
</xsl:template>
</xsl:stylesheet>

But i am getting an error in my application(working fine in http://xsltransform.net/). The error is

Microsoft Dynamics NAV
A call to System.Xml.Xsl.XslTransform.Load failed with this message: Expression must evaluate to a node-set.

If you’re using Microsoft, maybe this example could be a bit better for you

The issue was with the Dotnet Automation Variable. The error was not meaning ful. The automation variable was System.Xml.Xsl.XslTransform

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.