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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:14:18+00:00 2026-06-11T21:14:18+00:00

I want to add an element to source xml. Example: Source <?xml version=1.0 encoding=UTF-8

  • 0

I want to add an element to source xml.

Example:
Source

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <DataArea>
        <PurchaseOrder>
            <PurchaseOrderLine>
                <DocumentReference type="customersReference1">
                    <DocumentID>
                        <ID>23423</ID>
                    </DocumentID>
                </DocumentReference>
                <Item>
                    <CustomerItemID>
                        <!-- ArtNr -->
                        <ID>444</ID>
                    </CustomerItemID>
                </Item>
                <Quantity unitCode="PCE">17.3</Quantity>
            </PurchaseOrderLine>
        </PurchaseOrder>
    </DataArea>

I want to add element

<LineNumber>10</LineNumber>

to

DataArea/PurchaseOrder/PurchaseOrderLine/

So first solution will be copying all data from original xml and then LineNumber like

<xsl:copy>
    <xsl:apply-templates select="DocumentReference"/>
    <xsl:apply-templates select="Item"/>
    <xsl:apply-templates select="Quantity"/>
        <!-- ADD HERE LINENUMBER -->
</xsl:copy>

How can I add LineNumber without manually copying all elements?

  • 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-11T21:14:19+00:00Added an answer on June 11, 2026 at 9:14 pm

    This is straight-forward, just by adding an extra matching template to the standard XSLT Identity Transform

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

    This just copies the element, and all its children, but adds the new LineNumber element too.

    Here is the full XSLT

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
       <xsl:output method="xml" indent="yes"/>
    
       <xsl:template match="PurchaseOrderLine">
          <xsl:copy>
             <xsl:apply-templates select="@*|node()"/>
             <LineNumber>10</LineNumber>
          </xsl:copy>
       </xsl:template>
    
       <xsl:template match="@*|node()">
          <xsl:copy>
             <xsl:apply-templates select="@*|node()"/>
          </xsl:copy>
       </xsl:template>
    </xsl:stylesheet>
    

    When applied to your XML, the following is output

    <DataArea>
       <PurchaseOrder>
          <PurchaseOrderLine>
             <DocumentReference type="customersReference1">
                <DocumentID>
                   <ID>23423</ID>
                </DocumentID>
             </DocumentReference>
             <Item>
                <CustomerItemID><!-- ArtNr -->
                   <ID>444</ID>
                </CustomerItemID>
             </Item>
             <Quantity unitCode="PCE">17.3</Quantity>
             <LineNumber>10</LineNumber>
          </PurchaseOrderLine>
       </PurchaseOrder>
    </DataArea>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using this source document: <?xml version=1.0 encoding=UTF-8?> <Root> <Element1 id=UniqueId1> <SubElement1/> <SubElement2> <LeafElement1/> <LeafElement1/>
This is my xml file. I want to add a new element to all
I'm having a bit o' trouble... Here is my mappings.xml file... <?xml version=1.0 encoding=utf-8?>
I want to add and remove div element using jquery and adding of div
I want to add a rel attribute of the element matching the array, so
I want to add a child node to an element in XmlDocument. For the
I would like to add an element to jquery.colorbox.js(want to do some fancey styling)
I want to add style in ASP.NET textbox control. I couldn't find textbox element
I have a source piece of xml into which I want to insert multiple
I want to parse the xml file to get the root element. Then append

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.