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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:10:40+00:00 2026-05-17T18:10:40+00:00

Is it possible to do a find and replace to the attributes of a

  • 0

Is it possible to do a find and replace to the attributes of a xml element? I want to change the directory that is being pointed to by a href:

From:

<image href="./views/screenshots/page1.png">

to

<image href="screenshots/page1.png"> 

And from:

<image href="./screenshots/page2.png">

to

<image href="screenshots/page2.png">

So by getting rid of all “./” that belong to the href of all image tags, but only the image tags. And furthermore, get rid of first folder if it is not named “screenshots”. Is there a simple way to do this in one go?

  • 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-17T18:10:41+00:00Added an answer on May 17, 2026 at 6:10 pm

    This transformation:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
    
     <xsl:template match="node()|@*">
      <xsl:copy>
       <xsl:apply-templates select="node()|@*"/>
      </xsl:copy>
     </xsl:template>
    
     <xsl:template match="image/@href[starts-with(.,'./screenshots/')]">
      <xsl:attribute name="href">
       <xsl:value-of select="substring(.,3)"/>
      </xsl:attribute>
     </xsl:template>
    
      <xsl:template match=
       "image/@href
         [starts-with(.,'./')
         and not(starts-with(substring(.,3), 'screenshots/'))
         ]">
      <xsl:attribute name="href">
       <xsl:value-of select="substring-after(substring(.,3),'/')"/>
      </xsl:attribute>
     </xsl:template>
    
    
     <xsl:template priority="10"
          match="image/@href[starts-with(.,'./views/')]">
      <xsl:attribute name="href">
       <xsl:value-of select="substring(.,9)"/>
      </xsl:attribute>
     </xsl:template>
    </xsl:stylesheet>
    

    when applied on this XML document:

       <t>
        <image href="./views/screenshots/page1.png"/>
        <image href="./screenshots/page2.png"/>
        <load href="./xxx.yyy"/>
        <image href="ZZZ/screenshots/page1.png"/>
       </t>
    

    produces the wanted result:

    <t>
        <image href="screenshots/page1.png"/>
        <image href="screenshots/page2.png"/>
        <load href="./xxx.yyy"/>
        <image href="ZZZ/screenshots/page1.png"/>
    </t>
    

    Do note:

    1. The use and overriding of the identity rule. This is the most fundamental and most powerful XSLT design pattern.

    2. Only href attributes of image elements are modified.

    3. Only href attributes that start with the string "./" or the string "./{something-different-than-screenshots}/" are processed in a special way (by separate templates).

    4. All other nodes are only processed by the identity template.

    5. This is a pure “push style” solution.

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

Sidebar

Related Questions

Possible Duplicate: Find and Replace more than 1 word? I want to use jQuery
It would be possible to find the nearest element, and then replace it's inner
I want to find First Word matching from Given Text and replace with another
Is it possible to find and replace in selected text in Snow Leopard Xcode
Possible Duplicate: How do I write a regex to find and replace मेरा नाम
Is it possible to find out which page the user was previously browsing from
Is it possible to find the second maximum number from an array of integers
Is it possible to find bluetooth-enabled devices near my iphone from an app? I
Is it possible to replace to upper case in Visual Studio using Find and
Is it possible to find all <p> tabs in a string and replace them

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.