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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:13:26+00:00 2026-05-25T15:13:26+00:00

I am trying to understand if there is a way to modify an xml

  • 0

I am trying to understand if there is a way to modify an xml document using XSLT or are there any other better approaches than XSLT?

Say, I have an xml like so:

<feed xmlns="http://www.w3.org/2005/Atom">
<id>http://libx.org/libx2/libapps</id>
<entry>
<id>http://libx.org/libx2/libapps/2</id>
</entry>
<entry>
<id>http://libx.org/libx2/libapps/3</id>
</entry>
</feed>

I would like to do the following actions:

  1. Modify feed:id to (remove the text of feed:id)
  2. Modify entry:id values such that the last number value after “/” remains.

The result xml should look something like so:

<feed xmlns="http://www.w3.org/2005/Atom">
<id></id>
<entry>
<id>2</id>
</entry>
<entry>
<id>3</id>
</entry>
</feed>

Thanks,
Sony

  • 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-25T15:13:26+00:00Added an answer on May 25, 2026 at 3:13 pm

    I. XSLT 1.0 solution:

    This XSLT 1.0 transformation works with any url without having any assumptions about all URLs haing a common starting substring:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:x="http://www.w3.org/2005/Atom">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:template match="node()|@*">
         <xsl:copy>
           <xsl:apply-templates select="node()|@*"/>
         </xsl:copy>
     </xsl:template>
    
     <xsl:template match="x:feed/x:id/node()"/>
    
     <xsl:template match="x:entry/x:id/text()" name="eatSlashes">
      <xsl:param name="pText" select="."/>
    
      <xsl:choose>
       <xsl:when test="not(contains($pText, '/'))">
        <xsl:value-of select="$pText"/>
       </xsl:when>
       <xsl:otherwise>
        <xsl:call-template name="eatSlashes">
         <xsl:with-param name="pText" select=
                       "substring-after($pText, '/')"/>
        </xsl:call-template>
       </xsl:otherwise>
      </xsl:choose>
     </xsl:template>
    </xsl:stylesheet>
    

    when applied on the provided XML document:

    <feed xmlns="http://www.w3.org/2005/Atom">
        <id>http://libx.org/libx2/libapps</id>
        <entry>
            <id>http://libx.org/libx2/libapps/2</id>
        </entry>
        <entry>
            <id>http://libx.org/libx2/libapps/3</id>
        </entry>
    </feed>
    

    the wanted, correct result is produced:

    <feed xmlns="http://www.w3.org/2005/Atom">
       <id/>
       <entry>
          <id>2</id>
       </entry>
       <entry>
          <id>3</id>
       </entry>
    </feed>
    

    II. XSLT 2.0 solution:

    <xsl:stylesheet version="2.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:x="http://www.w3.org/2005/Atom">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:template match="node()|@*">
         <xsl:copy>
           <xsl:apply-templates select="node()|@*"/>
         </xsl:copy>
     </xsl:template>
    
     <xsl:template match="x:feed/x:id/node()"/>
    
     <xsl:template match="x:entry/x:id/text()">
      <xsl:sequence select="tokenize(.,'/')[last()]"/>
     </xsl:template>
    </xsl:stylesheet>
    

    when applied on the same XML document (above), the same correct result is produced:

    <feed xmlns="http://www.w3.org/2005/Atom">
       <id/>
       <entry>
          <id>2</id>
       </entry>
       <entry>
          <id>3</id>
       </entry>
    </feed>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand if there is a way to get a hold
I am trying to understand is there a way I can record calls incoming
I am trying to understand how to use reference parameters. There are several examples
I'm trying to understand the difference between sequences and lists. In F# there is
I am new to Dojo and trying to understand how to handle events. There
Trying to understand Ruby a bit better, I ran into this code surfing the
Is there any way to interrupt a Future without cancelling it? java doc API:
Is there a way to view the actual underlying xml data that the cookcomputing.xmlrpc.net
This is someone elses code that I am trying to understand and modify... The
I have a program that I am trying to understand but there is an

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.