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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:56:26+00:00 2026-05-23T05:56:26+00:00

I have an xml document with multiple nodes that looks something like this: <Result>

  • 0

I have an xml document with multiple nodes that looks something like this:

    <Result>
        <Url>http://www.mysite.com/Topic/1/</Url>
    </Result>
    <Result>
        <Url>http://www.mysite.com/Topic/2/</Url>
    </Result>
    <Result>
        <Url>http://www.mysite.com/Topic/3/</Url>
    </Result>

What I want to do is to retrieve the Topic ID after “Topic/” for all nodes. For the above example I am looking for the values 1,2 and 3. I can think of other ways to do it but I was wondering if there was a way to do it using XPath?

  • 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. Editorial Team
    Editorial Team
    2026-05-23T05:56:27+00:00Added an answer on May 23, 2026 at 5:56 am

    You can use substring-after paired with substring-before to just extract the number

    This is the expression

    substring-before(substring-after(.,'http://www.mysite.com/Topic/'),'/')
    

    Given your input (I added a root node to make it vaild)

    <xml>
      <Result>
        <Url>http://www.mysite.com/Topic/1/</Url>
      </Result>
      <Result>
        <Url>http://www.mysite.com/Topic/2/</Url>
      </Result>
      <Result>
        <Url>http://www.mysite.com/Topic/3/</Url>
      </Result>
    </xml>
    

    this transform illustrates the result you want

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output indent="yes" method="xml"/>
      <xsl:template match="@*|node()">
        <xsl:copy>
          <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
      </xsl:template>
      <xsl:template match="Url">
        <Topic>
          <xsl:value-of select="substring-before(substring-after(.,'http://www.mysite.com/Topic/'),'/')"/>
        </Topic>
      </xsl:template>
    </xsl:stylesheet>
    

    Output

    <xml>
      <Result>
        <Topic>1</Topic>
      </Result>
      <Result>
        <Topic>2</Topic>
      </Result>
      <Result>
        <Topic>3</Topic>
      </Result>
    </xml>
    

    Depending on the context, you should replace . in the expression above with the path you need to access your node.

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

Sidebar

Related Questions

Alright I have an xml document that looks something like this: <xml> <list> <partner>
I have an XML document something like ::: <?xml version=1.0 encoding=utf-8?> <?mso-application progid=Excel.Sheet?> <Workbook
I have an xml document that is constructed pretty poorly-- instead of child nodes,
I have an XML document, something like <root> <item>_x0034_SOME TEXT</item> <item>SOME_x0020_TEXT</item> <item>SOME_x0020_TEXT_x0032_</item> </root> I'm
I have a XML document with my data in it, multiple entries for the
I have an XML document that I'm trying to style via CSS. A relevant
I have an XML document looking similar to this: <items> <item cat=1 owner=14>bla</item> <item
I have an xml document object that I need to convert into a string.
I have an XML document with a default namespace indicated at the root. Something
I have implemented a csv file builder that takes in an xml document applies

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.