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

  • Home
  • SEARCH
  • 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 8274123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:38:42+00:00 2026-06-08T07:38:42+00:00

I want to change from one XML (XHTML) file to another using XSLT. In

  • 0

I want to change from one XML (XHTML) file to another using XSLT. In the new XML file I have to remove/add/modify some elements. So for that I created one identity.xsl file, which copies the entire source file and then I created a new XSLT which includes identity.xsl and then in that new XSLT I’m trying to do the modifications. I’m able to eliminate a few attributes, which are not required, by passing a template match which does nothing but I’m unable to add the new attributes in the existing tags and also unable to add the new elements at the specific location (with closing tags at particular location).

My Original file:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-type" content="text/html;  charset=utf-8" />
</head>

<body>
  <div id="o">
    <div id="nd">
      <p>1</p>
    </div>

    <div class="TF id="id12">
      <element1 name="abc" src="abc.jpg"></script>
      <input type="radio" id="1" event="xyz">
      <div class="q">
        <br/>
        <div id="ta3" class="block">
          <span style="a">ABC</span>
        </div>
        <br/>T <input/> F <input/>
        <div id="sf">
          <div id="ta3">
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
</body>
</html>

Required file:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-type" content="text/html;  charset=utf-8" />
</head>

<!--HAVE TO AD THESE TWO ELEMENTS-->
<element add="xyz" id="23">
<element add="xyz" id="24">

<!--ADD ATTRIBUTES IN BODY TAG-->
<body onLoad="ada" bgcolor="pink">

  <div id="o">
    <div id="nd">
      <p>1</p>
    </div>

    <div class="TF id="id12">

      <!--HAVE TO UPATE THE VALUE OF SRC ATTRIBUTE -->
      <element1 name="abc" src="xyz.jpg"></script>

      <!--ADD THIS FORM ELEMENT WITH ATTRIBUTE-->
      <form name="form">
        <input type="radio" id="1" event="xyz">
        <div class="q">
          <br/>
          <div id="ta3" class="block">
            <span style="a">ABC</span>
          </div>

          <br/>T 
          <!--ADD TABLE/TR/TD TAG-->
          <table>
            <tr>
              <td>
                <input/>
              </td>
            </tr>
            <tr>
              </td>
              F <input/>
              </td>
            </tr>
          </table>

          <div id="sf">
            <div id="ta3">
            </div>
          </div>
        </div>

        <!--ADD INPUT TAG-->
        <input type="submit" value="Done"/>

      </div>
    </div>

    <!--CLOSE FORM TAG-->
  </form>
</div>
</body>
</html>

XSLT:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <!-- Import the identity transformation. -->
  <xsl:import href="identity.xsl"/>

  <xsl:template match="body">
    <body>
      <xsl:apply-templates select="body">
      </xsl:apply-templates>
    </body>
  </xsl:template>

  <xsl:template match="body">
    <body onLoad="ada" bgcolor="pink"></body>
  </xsl:template>

  <!--REMOVES THE MATCHING ATTRIBUTE and DOES THE JOB-->
  <xsl:template match="@attr"> </xsl:template>

  <xsl:template match="input">
    <xsl:element name="input">
      <xsl:attribute name="type">submit</xsl:attribute>
      <xsl:attribute name="value">Done</xsl:attribute>
      <xsl:apply-templates />
    </xsl:element>
  </xsl:template>

</xsl:stylesheet>
  • 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-06-08T07:38:43+00:00Added an answer on June 8, 2026 at 7:38 am

    Your input document was so full of formation errors, I’ve had to take the risk of guessing your intentions. Please see the transform solution below. I deliberately did not include the insertion of the table elements around your comment “ADD TABLE/TR/TD TAG”, as this section seemed so nutty that any solution that I provided for you here would likely be a wrong interpretation of your required rules of transformation.

    This XSLT 1.0 style-sheet …

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:xhtml="http://www.w3.org/1999/xhtml"
     xmlns="http://www.w3.org/1999/xhtml"
     exclude-result-prefixes="xhtml">
    <xsl:output method="xml" indent="yes" encoding="UTF-8"/>
    <xsl:strip-space elements="*" />
    
    <xsl:template match="@*|node()">
     <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
     </xsl:copy>
    </xsl:template>
    
    <xsl:template match="xhtml:body">
      <element add="xyz" id="23" />
      <element add="xyz" id="24" />
     <body onLoad="ada" bgcolor="pink">
      <xsl:apply-templates select="@*|node()"/>
      </body>
    </xsl:template>
    
    <xsl:template match="xhtml:element1[@name='abc']/@src">
      <xsl:attribute name="src">xyz.jpg</xsl:attribute>  
    </xsl:template>
    
    <xsl:template match="xhtml:input[@id='1']">
      <form name="form">
       <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
       </xsl:copy>
       <xsl:apply-templates select="following-sibling::xhtml:div[1]" mode="inside-form"/> 
      </form>
    </xsl:template>
    
    <xsl:template match="xhtml:div[ preceding-sibling::xhtml:*[1]
       /self::xhtml:input[@id='1']]"/>
    
    <xsl:template match="xhtml:div" mode="inside-form">
     <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
     </xsl:copy>
     <input type="submit" value="Done"/> 
    </xsl:template>
    
    </xsl:stylesheet>
    

    … will take this input document …

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
     <meta http-equiv="Content-type" content="text/html;  charset=utf-8" />
    </head>
    <body>
     <div id="o">
      <div id="nd">
       <p>1</p>
      </div>
      <div class="TF" id="id12">
       <element1 name="abc" src="abc.jpg"/>
       <input type="radio" id="1" event="xyz"/>
       <div class="q">
        <br/>
        <div id="ta3" class="block">
         <span style="a">ABC</span>
        </div>
        <br/>T <input/> F <input/>
        <div id="sf">
         <div id="ta3">
         </div>
        </div>
       </div>
      </div>
     </div>
    </body>
    </html>
    

    …and yield this output document …

    <?xml version="1.0" encoding="utf-8"?>
    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <meta http-equiv="Content-type" content="text/html;  charset=utf-8" />
      </head>
      <element add="xyz" id="23" />
      <element add="xyz" id="24" />
      <body onLoad="ada" bgcolor="pink">
        <div id="o">
          <div id="nd">
            <p>1</p>
          </div>
          <div class="TF" id="id12">
            <element1 name="abc" src="xyz.jpg" />
            <form name="form">
              <input type="radio" id="1" event="xyz" />
              <div class="q">
                <br />
                <div id="ta3" class="block">
                  <span style="a">ABC</span>
                </div>
                <br />T <input /> F <input /><div id="sf"><div id="ta3" /></div></div>
              <input type="submit" value="Done" />
            </form>
          </div>
        </div>
      </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have one xml file successfully parsed my before. now i am change
I have an XML document, and I want to change the values for one
Using a WPF expander, I want the Header to change from See More to
I want to change order in plist file not programmatically but from xcode. Is
I simply want to change a variable of an object from another class. I
What i want to do is to change two values from the Preferences File
I have a window in which I want to add/remove component and resize the
I have XML coming from a source that I can't change. They send it
I have an XML file containing one (or more) key/value pairs. For each of
I have a XSD file, from which I want to generate C# and Java

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.