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

  • SEARCH
  • Home
  • 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 7819371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:55:18+00:00 2026-06-02T06:55:18+00:00

I want to evaluate the content of a string variable as a operation. My

  • 0

I want to evaluate the content of a string variable as a operation.

My variable it’s this string:
1+1+0

I want to make the operation and get the value 2.

Thanks in advance,
Gustavo

  • 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. Editorial Team
    Editorial Team
    2026-06-02T06:55:21+00:00Added an answer on June 2, 2026 at 6:55 am

    In XSLT 2.0 this can be done by using tokenize(), number() and sum() functions, for example the below. Note that I included possible whitespaces surrounding the + signs.

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    
        <xsl:variable name="test1">1+1+0</xsl:variable>
        <xsl:variable name="test2"> 3 + 
        5   +           12 </xsl:variable>
    
        <xsl:template match="/">
            <xsl:variable name="testSplit1" select="tokenize($test1,'\s*\+\s*')"/>
            <xsl:variable name="testSplitNum1">
                <xsl:for-each select="$testSplit1">
                    <item><xsl:value-of select="number(.)"/></item>
                </xsl:for-each>
            </xsl:variable>
    
            <xsl:variable name="testSplit2" select="tokenize($test2,'\s*\+\s*')"/>
            <xsl:variable name="testSplitNum2">
                <xsl:for-each select="$testSplit2">
                    <item><xsl:value-of select="number(.)"/></item>
                </xsl:for-each>
            </xsl:variable>
    
            <root>
                <items1><xsl:copy-of select="$testSplitNum1"/></items1>
                <sum1><xsl:value-of select="sum($testSplitNum1/item)"/></sum1>
                <items2><xsl:copy-of select="$testSplitNum2"/></items2>
                <sum2><xsl:value-of select="sum($testSplitNum2/item)"/></sum2>
            </root>
    
        </xsl:template>
    
    </xsl:stylesheet>
    

    The result (with dummy input file) is

    <?xml version="1.0" encoding="UTF-8"?>
    <root>
        <items1>
            <item>1</item>
            <item>1</item>
            <item>0</item>
        </items1>
        <sum1>2</sum1>
        <items2>
            <item>3</item>
            <item>5</item>
            <item>12</item>
        </items2>
        <sum2>20</sum2>
    </root>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I cant find an expression to evaluate a part of a string. I want
want to know why String behaves like value type while using ==. String s1
This is my XML file, and i want to know how to get the
Let's say I want to generate this output: public String toString() { return this.getFirstName()
I usually write python in emacs. I'll often want to re-evaluate my file, which
I want to run Protovis javascript from Java and get the evaluated SVG code.
Want to code a key pad for an calculator. What I want to make
want to rewrite urls like site.com/software to wp-content/themes/dir/software.php and something is not working.. Here's
Hi I need to evaluate if a server supports gzip compression. Therefore I want
When you have an NSArray and you want to evaluate and change the elements,

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.