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

Related Questions

I have an interesting problem. The basis of the problem is that my last
I have an interesting problem, which is a function that returns a Dictionary<String,HashSet<String>> .
We have an interesting problem that I was hoping someone could help to shed
I have an interesting problem, that i am sure has a simple answer, but
I have a rather interesting problem. I have a parent page that will create
I have an interesting problem, I have two web services defined in a spring-conf.xml
I have an interesting problem here. I have a MySql database table that has
I have an interesting problem.. I have a Form that launches another Form (2)
I have an interesting problem. I currently have a basic template library that renders
I have an interesting problem to solve here that may require some creative direction.

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.