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 153617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:49:57+00:00 2026-05-11T09:49:57+00:00

I have an XML file where the number are comma-separated <foo> <bar val=1,23/> <bar

  • 0

I have an XML file where the number are comma-separated

<foo>   <bar val='1,23'/>   <bar val='4,56'/>   <bar val='7,89'/> </foo> 

I would like to make a sum over /foo/bar/@val values in XSLT, but I am a bit stuck the formatting. Does anyone knows what would be the proper syntax?

  • 1 1 Answer
  • 0 Views
  • 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-11T09:49:58+00:00Added an answer on May 11, 2026 at 9:49 am

    I am guessing, that the value specified in a 'val' attribute is a number that has comma instead of a decimal point.

    Several solutions are possible:

    I. XSLT 1.0

    This transformation:

    <xsl:stylesheet version='1.0'  xmlns:xsl='http://www.w3.org/1999/XSL/Transform'  xmlns:ext='http://exslt.org/common'  >   <xsl:output method='text'/> <!--                                           -->       <xsl:template match='foo'>       <xsl:variable name='vrtfBars'>         <xsl:for-each select='bar'>           <bar val='{translate(@val, ',', '.')}'/>         </xsl:for-each>       </xsl:variable> <!--                                           -->       <xsl:value-of select=        'sum(ext:node-set($vrtfBars)/*/@val)'/>     </xsl:template> </xsl:stylesheet> 

    when applied on the originally-provided XML document:

    <foo>     <bar val='1,23'/>     <bar val='4,56'/>     <bar val='7,89'/> </foo> 

    produces the wanted result:

    13.68 

    II. XSLT 2.0

    This transformation:

    <xsl:stylesheet version='2.0'  xmlns:xsl='http://www.w3.org/1999/XSL/Transform'  xmlns:xs='http://www.w3.org/2001/XMLSchema'  exclude-result-prefixes='f xs'  >  <xsl:output method='text'/> <!--                                           -->  <xsl:template match='foo'>   <xsl:sequence select=    'sum(bar/@val/number(translate(., ',', '.')))'     />  </xsl:template> </xsl:stylesheet> 

    when applied on the same XML document, produces the same correct result:

    13.68

    III. FXSL 2.x

    This transformation:

    <xsl:stylesheet version='2.0'  xmlns:xsl='http://www.w3.org/1999/XSL/Transform'  xmlns:xs='http://www.w3.org/2001/XMLSchema'  xmlns:f='http://fxsl.sf.net/'  xmlns:my='my:fun'  exclude-result-prefixes='my f xs'  >    <xsl:import href='../f/func-transform-and-sum.xsl'/> <!--                                           -->  <xsl:output method='text'/> <!--                                           -->  <xsl:template match='foo'>   <xsl:sequence select=    'sum(         f:transform-and-sum(my:makeNum(), bar/@val )         )'     />  </xsl:template> <!--                                           -->  <xsl:function name='my:makeNum' as='xs:double'>    <xsl:param name='psNum' as='xs:string'/> <!--                                           -->    <xsl:sequence select='number(translate($psNum, ',', '.'))'/>  </xsl:function> <!--                                           -->  <xsl:function name='my:makeNum' as='element()'>    <my:makeNum/>  </xsl:function> <!--                                           -->  <xsl:template match='my:makeNum' as='xs:double' mode='f:FXSL'>    <xsl:param name='arg1' as='xs:string'/> <!--                                           -->    <xsl:sequence select='my:makeNum($arg1)'/>  </xsl:template> </xsl:stylesheet> 

    when applied on the same XML document produces the same correct result:

    13.68

    The last solution is more flexible and can be used successfully when a more complex transformation of the values is needed before summing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 72k
  • Answers 72k
  • 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
  • added an answer you can add the google analytics stuff like on any… May 11, 2026 at 1:43 pm
  • added an answer It's cookie-less sessions. May 11, 2026 at 1:43 pm
  • added an answer do changes in Calculator and main function. struct Calculator {… May 11, 2026 at 1:43 pm

Related Questions

No related questions found

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.