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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:50:30+00:00 2026-05-11T19:50:30+00:00

It seems with all the rich amount of function in xpath that you could

  • 0

It seems with all the rich amount of function in xpath that you could do an “if” . However , my engine keeps insisting “there is no such function” , and I hardly find any documentation on the web (I found some dubious sources , but the syntax they had didn’t work)

I need to remove ‘:’ from the end of a string (if exist), so I wanted to do this:

if (fn:ends-with(//div [@id='head']/text(),': '))
            then (fn:substring-before(//div [@id='head']/text(),': ') )
            else (//div [@id='head']/text())

Any advice?

  • 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-11T19:50:30+00:00Added an answer on May 11, 2026 at 7:50 pm

    Yes, there is a way to do it in XPath 1.0:

    concat(
      substring($s1, 1, number($condition)      * string-length($s1)),
      substring($s2, 1, number(not($condition)) * string-length($s2))
    )
    

    This relies on the concatenation of two mutually exclusive strings, the first one being empty if the condition is false (0 * string-length(...)), the second one being empty if the condition is true. This is called "Becker’s method", attributed to Oliver Becker (original link is now dead, the web archive has a copy).

    In your case:

    concat(
      substring(
        substring-before(//div[@id='head']/text(), ': '),
        1, 
        number(
          ends-with(//div[@id='head']/text(), ': ')
        )
        * string-length(substring-before(//div [@id='head']/text(), ': '))
      ),
      substring(
        //div[@id='head']/text(), 
        1, 
        number(not(
          ends-with(//div[@id='head']/text(), ': ')
        ))
        * string-length(//div[@id='head']/text())
      )
    )
    

    Though I would try to get rid of all the "//" before.

    Also, there is the possibility that //div[@id='head'] returns more than one node.
    Just be aware of that — using //div[@id='head'][1] is more defensive.

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

Sidebar

Related Questions

It seems that while I strive to maintain OO principles, it all seems so
I am working on a cross platform OpenGL project and it seems that all
Ive read about it and to be honest it all seems like a bunch
I'm using the Asp.net change password control in my application and all seems to
Ok, so, im having trouble with this program im writing, it all seems to
hello all this seems to be my problem I have a table in mysql
This seems to happen all the time to me: I work on the parent
firstly i have searched a lot and all topics seems to be C# :
Seems when I make move refactoring all my junit tests lays on its old
SQLAlchemy seems really heavyweight if all I use is MySQL. Why are convincing reasons

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.