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
  • 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-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

I have an XML document that looks like this: <kmsg xmlns=http://url1 xmlns:env=url1 xmlns:xsi=http://www.w3.org/2001/XMLSchemainstance xsi:schemaLocation=http://location
Alright I have an xml document that looks something like this: <xml> <list> <partner>
Say I have a xml document that looks like this <foo> <bar id=9 />
I have a XML document which looks something like this: <events> <event category=gymnastics subcategory=rhythmic
I have an XML document (an InfoPath form) that looks similar to this: <my:ClientMaintenance
I have an XML document something like ::: <?xml version=1.0 encoding=utf-8?> <?mso-application progid=Excel.Sheet?> <Workbook
In my Python app, I have an XML document that I'd like to transform
I have an xml document that is constructed pretty poorly-- instead of child nodes,
hi i have xml file whitch i want to parse, it looks something like
I have an XML Document with Nodes that can appear recursively within other nodes

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.