Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 146929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:41:27+00:00 2026-05-11T08:41:27+00:00

I have an interesting problem with XSL. We have an XML Input file that

  • 0

I have an interesting problem with XSL. We have an XML Input file that contains next to the content several settings that define how we output the content. Currently I’m struggling with the formatting of the numbers within the XSL file.

The following formats are possible:

  • 1,234.5
  • 1.234,5
  • 1234,5
  • 1234.5

I get these formats as above mentioned within my XML file:

<?xml version='1.0' encoding='UTF-8'?> <document>     <settings>         <DefaultCurrency>EUR</DefaultCurrency>         <DefaultDateFormat>DD.MM.YYYY</DefaultDateFormat>     <DefaultNumberFormat>1.250,65</DefaultNumberFormat>     <AllowOrdering>true</AllowOrdering> </settings> <productlist>     <item>         <product>             <productid>Product1</productid>             <weight>0.123</weight>         </product>         <customerprice>123.03</customerprice>     </item>     <item>         <product>             <productid>Product2</productid>             <weight>12312.123</weight>         </product>         <customerprice>12.00</customerprice>     </item>     <item>         <product>             <productid>Product3</productid>             <weight>12.123</weight>         </product>         <customerprice>13.23</customerprice>     </item> </productlist> </document> 

I have tried to get this working with the following XSL file, but I cannot get it to give me the correct results (when the DefaultNumberFormat in the XML is changed the formatting must also be changed).

<?xml version='1.0' encoding='UTF-8'?> <xsl:stylesheet version='2.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:fn='http://www.w3.org/2005/xpath-functions'>     <xsl:decimal-format name='numberformat1' decimal-separator='.' grouping-separator=','/>     <xsl:decimal-format name='numberformat2' decimal-separator=','/>     <xsl:decimal-format name='numberformat3' decimal-separator=',' grouping-separator='.'/>     <xsl:decimal-format name='numberformat4' decimal-separator='.'/>     <xsl:template match='productlist'>         <xsl:apply-templates select='item'/>     </xsl:template>     <xsl:template match='item'> ItemID: <xsl:value-of select='product/productid'/> Weigh:  <xsl:choose>             <xsl:when test='/document/settings/DefaultNumberFormat = '1,250.65''>                 <xsl:value-of select='format-number(product/weight, '#,##0.000', 'numberformat1')'/>             </xsl:when>             <xsl:when test='/document/settings/DefaultNumberFormat = '1250,65''>                 <xsl:value-of select='format-number(product/weight, '#,##0.000', 'numberformat2')'/>             </xsl:when>             <xsl:when test='/document/settings/DefaultNumberFormat = '1.250,65''>                 <xsl:value-of select='format-number(product/weight, '#,##0.000', 'numberformat3')'/>             </xsl:when>             <xsl:when test='/document/settings/DefaultNumberFormat = '1250.65''>                 <xsl:value-of select='format-number(product/weight, '#,##0.000', 'numberformat4')'/>             </xsl:when>         </xsl:choose>     </xsl:template>     <xsl:template match='settings/*'/> </xsl:stylesheet> 

I hope somebody can help me here, I think I somehow got a mind twist in how to combine the format-number and the number format…

Thanks, Martijn

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T08:41:28+00:00Added an answer on May 11, 2026 at 8:41 am

    The following transformation calculates which number-format to use:

    <xsl:stylesheet version='1.0'  xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>     <xsl:variable name='vDoc' select='/'/>      <xsl:variable name='vDFormats'>         <dFormat spec='1,250.65' name='numberformat1'/>         <dFormat spec='1250,65' name='numberformat2'/>         <dFormat spec='1.250,65' name='numberformat3'/>         <dFormat spec='1250.65' name='numberformat4'/>     </xsl:variable>      <xsl:variable name='vDefFormats' select=      'document('')/*/xsl:variable                       [@name='vDFormats']'/>      <xsl:variable name='vtheFormatName' select=      'string($vDefFormats/*               [@spec = $vDoc/*/settings/DefaultNumberFormat]                                    /@name            )    '/>      <xsl:decimal-format name='numberformat1'           decimal-separator='.' grouping-separator=','/>     <xsl:decimal-format name='numberformat2'           decimal-separator=','/>     <xsl:decimal-format name='numberformat3'           decimal-separator=',' grouping-separator='.'/>     <xsl:decimal-format name='numberformat4'           decimal-separator='.'/>      <xsl:template match='productlist'>         <xsl:apply-templates select='item'/>     </xsl:template>      <xsl:template match='item'>ItemID: <xsl:text/>          <xsl:value-of select='product/productid'/> Weigh: <xsl:text/>          <xsl:value-of select=         'format-number(product/weight,                         '#,##0.000',                         $vtheFormatName)'/>     </xsl:template>      <xsl:template match='settings/*'/> </xsl:stylesheet> 

    When applied on the following XML document:

    <document>   <settings>     <DefaultNumberFormat>1,250.65</DefaultNumberFormat>   </settings>      <productlist>       <item>         <product>           <productid>30</productid>           <weight>2530.45</weight>         </product>       </item>     </productlist> </document> 

    the wanted result is produced:

    ItemID: 30 Weigh: 2,530.450 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 267k
  • Answers 267k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The DataSource property expects a collection. The value you are… May 13, 2026 at 12:58 pm
  • Editorial Team
    Editorial Team added an answer That's an unclear question. If I understand correctly you want… May 13, 2026 at 12:58 pm
  • Editorial Team
    Editorial Team added an answer Try this technique - include your stylesheet both ways. Include… May 13, 2026 at 12:58 pm

Related Questions

So we have this web app where we support UTF8 data. Hooray UTF8. And
How do I apply a change to text in an element without losing its
I've got a struts2 action that responds to an AJAX request by taking some
I'm using an XsltCompiledTransform to transform some XML into a fragment of HTML (not

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.