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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:48:08+00:00 2026-06-09T02:48:08+00:00

how to do cut and paste in xslt? suppose my xml like this, <root>

  • 0

how to do cut and paste in xslt? suppose my xml like this,

  <root>
    <header>
      some nodes
    </header>
    <body>
    <p>
      some text
    <link>1</link>
      <note xml:id="c5-note-0001" numbered="no">text</note>
    </p>
    <p>
      some text
      <link>2</link>
      <figure>
        <note xml:id="c5-note-0003">text</note>
      </figure>
      <note xml:id="c5-note-0002">text</note>
    </p>
    <tabular>
      <note xml:id="c5-note-0004" numbered="no">text</note>
    </tabular>
    <p>
      some text
      <link>3</link>
      <notegroup>
        <note xml:id="c5-note-0006">text</note>
      </notegroup>
      <note xml:id="c5-note-0005">text</note>
    </p>
    <p>
      some text
      <link>4</link>
      <note xml:id="c5-note-0007">text</note>
    </p>
    </body>
  </root>

my expected output is,

  <root>
    <header>
      some nodes
    </header>
    <body>
      <p>
        some text
        <link>1</link>
        <note xml:id="c5-note-0001" numbered="no">text</note>
      </p>
      <p>
        some text
        <link>2</link>
        <figure>
            <note xml:id="c5-note-0003">text</note>
        </figure>
        <notenum>1</notenum>
      </p>
      <tabular>
        <note xml:id="c5-note-0004" numbered="no">text</note>
      </tabular>
      <p>
        some text
        <link>3</link>
        <notegroup>
          <note xml:id="c5-note-0006">text</note>
        </notegroup>
        <notenum>2</notenum>
      </p>
      <p>
        some text
        <link>4</link>
        <notenum>3</notenum>
      </p>
      <newnote>
        <note xml:id="c5-note-0002">text</note>
        <note xml:id="c5-note-0005">text</note>
        <note xml:id="c5-note-0007">text</note>
      </newnote>
    </body>
  </root>

i need to create a new node newnote before the end of body tag and cut and paste the note node into that and need to generate a notenum node instead of that note.

i need to do this only within the p node. if the note comes under tabular, figure and notegroup then no need to do anything.

if note contains attribute like numbered="no" then no need to do anything.

i am using the following xslt(just to show the template match that i am using),

  <?xml version="1.0" encoding="utf-8"?>
   <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
  >
      <xsl:output method="xml" indent="yes"/>

      <xsl:template match="@* | node()">
          <xsl:copy>
              <xsl:apply-templates select="@* | node()"/>
          </xsl:copy>
      </xsl:template>
    <xsl:template match ="figure">
      some operation
    </xsl:template>
    <xsl:template match ="tabular">
      some operation
    </xsl:template>
    <xsl:template match ="notegroup">
      some operation
    </xsl:template>
  </xsl:stylesheet>

thanks in advance.

  • 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-09T02:48:10+00:00Added an answer on June 9, 2026 at 2:48 am

    In general, it’s beneficial in XSLT to imagine “cut and paste” as what it actually is, namely “copy and paste and delete the original”.

    i need to create a new node newnote before the end of body tag and cut and paste the note node into that

    What you want to do is adapt the <body> element so it contains, after its (possibly otherwise modified) original contents, a new <newnote> element. Therefore, add a new template for the <body> element:

    <xsl:template match="body">
    </xsl:template>
    

    As mentioned before, you want to basically take over the original contents. As that original contents may still be processed by other templates, we’ll use <xsl:apply-tepmlates> here:

    <xsl:template match="body">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
    

    After the original contents, you want to insert the new element:

    <xsl:template match="body">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
        <newNote>
        </newNote>
    </xsl:template>
    

    Finally, in this element, you want a copy of all the described <note> elements, which can be achieved with an <xsl:for-each> loop:

    <xsl:template match="body">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
        <newnote>
            <xsl:for-each select="p/note[not(@numbered = 'no')]">
                <xsl:copy-of select="."/>
            </xsl:for-each>
        </newnote>
    </xsl:template>
    

    and need to generate a notenum node instead of that note.

    This can be done with a template replacing the respective <note> elements:

    <xsl:template match="p/note[not(@numbered = 'no')]">
        <notenum><xsl:value-of select="count(preceding::note[parent::p][not(@numbered = 'no')]) + 1"/></notenum>
    </xsl:template>
    

    Insert the new <notenum> element instead and use the <xsl:value-of> command to output a computed value. The value is the number of preceding <note> elements that match your restrictions plus one.

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

Sidebar

Related Questions

I have requirement to disable copy/paste/cut operations on a textbox. For this purpose I
This is my VERY FIRST Makefile and so I have cut and paste junk
Can anyone tell me why this bash script works if I cut and paste
I would like to prevent copy, cut and paste in my TEdit . How
I'm trying to cut a xml into parts and then apply it some transformations.
A user selects a portion of an image for a cut and paste operation.
How to cut part from this string... abb.c.d+de.ee+f.xxx+qaa.+.,,s, ... where i know position by
Is it possible using some sort of client side code to detect cut and
I am displaying some HTML text in an Adobe AIR Application that I do
I am using the following cut/paste function to get the URL parameters. function getUrlVars()

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.