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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:44:01+00:00 2026-05-13T16:44:01+00:00

Given the following XML: <table> <col width=12pt/> <col width=24pt/> <col width=12pt/> <col width=48pt/> </table>

  • 0

Given the following XML:

<table>
  <col width="12pt"/>
  <col width="24pt"/>
  <col width="12pt"/>
  <col width="48pt"/>
</table>

How can I convert the width attributes to numeric values that can be used in mathematical expressions? So far, I have used substring-before to do this. Here is an example template (XSLT 2.0 only) that shows how to sum the values:

<xsl:template match="table">
    <xsl:text>Col sum: </xsl:text>
    <xsl:value-of select="sum(
        for $w 
        in col/@width 
        return number(substring-before($w, 'pt'))
     )"/>
</xsl:template>

Now my questions:

  • Is there a more efficient way to do the conversion than substring-before?
  • What if I don’t know the text after the numbers? Any way to do it without using regular expressions?
  • 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-05-13T16:44:01+00:00Added an answer on May 13, 2026 at 4:44 pm

    I found this answer from Dimitre Novatchev that provides a very clever XPATH solution that doesn’t use regex:

    translate(., translate(.,'0123456789', ''), '')
    

    It uses the nested translate to strip all the numbers from the string, which yields all other characters, which are used as the values for the wrapping translate function to strip out and return just the number characters.

    Applied to your template:

    <xsl:template match="table">
        <xsl:text>Col sum: </xsl:text>
        <xsl:value-of select="sum(
            for $w 
            in col/@width 
            return number(translate($w, translate($w,'0123456789', ''), ''))
         )"/>
    </xsl:template>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following repository URL from my pom.xml how can I determine what the
I have written the following piece of code that reads through a given xml-file
Given the following XML variable, how can I replace UNKNOWN in the StateCode node
Given the following XML: <Contact> <ContactID>41111-f15a-4fa1-b643-47877608f557</ContactID> <ContactStatus>ACTIVE</ContactStatus> <Name>ABC Ltd</Name> <EmailAddress>xxx@xxx.co</EmailAddress> <SkypeUserName>xxxdemo</SkypeUserName> <Addresses> <Address> <AddressType>STREET</AddressType>
Given the following XML structure: <root> <data>x</data> <details> <some_other_element>...</some_other_element> <collection> <element><a>1</a></element> <element><a>2</a></element> <element><a>3</a></element> <collection>
Given the following xml: <language>en-US</language> <provider>VenturesLLC</provider> <video> <original_spoken_locale>en-US</original_spoken_locale> <vendor_offer_code>TEST_VENDOR</vendor_offer_code> <release_date>2011-01-15</release_date> <title>Moving Forward</title> <vendor_id>ASDF_ING_2012</vendor_id> </video>
Given the following xml: <!-- file.xml --> <video> <original_spoken_locale>en-US</original_spoken_locale> <another_tag>somevalue</another_tag> </video> What would be
Given the following xml: <Title> <EST> <EST_Start_Date>2009-09-21</EST_Start_Date> <EST_End_Date>2015-12-31</EST_End_Date> <EST_Version> <Vendor_ID>asdf-200130</Vendor_ID> <Master_Type_HD_SD>SD</Master_Type_HD_SD> </EST_Version> <EST_Version> <Digital_SKU>205119</Digital_SKU>
Given the following XML, I would like to return all eventtitles where the eventtype
Given the following XML: <root> Pacman <format bold=1 italic=1>rules</format>! </root> What is a better

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.