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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:23:37+00:00 2026-06-09T08:23:37+00:00

In the below two ASNInPO’s po_nbr is same container_id under ASNInCtn is same and

  • 0

In the below two ASNInPO’s po_nbr is same container_id under ASNInCtn is same and item_id under ASNInItem is different. In this case two ASNInPO’s has to be merged and two ASNInCtn’s has to be merged into one tag.
This is my Input:

     <?xml version = '1.0' encoding = 'UTF-8'?>
 <ASNInDesc>
    <asn_nbr>ASN-1</asn_nbr>
    <ASNInPO>
      <po_nbr>PO-2</po_nbr>
      <ASNInCtn>
         <container_id>CONTAINER-2</container_id>
         <ASNInItem>
            <item_id>ITEM-2</item_id>
            <unit_qty>3</unit_qty>
         </ASNInItem>
      </ASNInCtn>
   </ASNInPO>
   <ASNInPO>
      <po_nbr>PO-2</po_nbr>
      <ASNInCtn>
         <container_id>CONTAINER-2</container_id>
         <ASNInItem>
            <item_id>ITEM-3</item_id>
            <unit_qty>3</unit_qty>
         </ASNInItem>
      </ASNInCtn>
   </ASNInPO>
  </ASNInDesc>

This is the desired output:

<?xml version = '1.0' encoding = 'UTF-8'?>
 <ASNInDesc>
    <asn_nbr>ASN-1</asn_nbr>
    <ASNInPO>
      <po_nbr>PO-2</po_nbr>
      <ASNInCtn>
         <container_id>CONTAINER-2</container_id>
         <ASNInItem>
            <item_id>ITEM-2</item_id>
            <unit_qty>3</unit_qty>
         </ASNInItem>
         <ASNInItem>
            <item_id>ITEM-3</item_id>
            <unit_qty>3</unit_qty>
         </ASNInItem>        
      </ASNInCtn>
   </ASNInPO>
 </ASNInDesc>

Please help me in solving this.

  • 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-09T08:23:40+00:00Added an answer on June 9, 2026 at 8:23 am

    Since this question is tagged with xslt-1.0, I’ll post a XSLT
    1.0 solution using the Muenchian grouping method. (Perhaps someone
    else will contribute a XSLT 2.0 solution. It might be instructive to
    compare them.)

    Let’s walk through the stylesheet.

    <xsl:stylesheet version="1.0" 
                    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="xml" indent="yes" encoding="UTF-8"/>
    

    Grouping 1: ASNInPO elements by po_nbr

    Since we want to group ASNInPO elements by their po_nbr, let’s
    start by defining a key which allows retrieving ASNInPO
    elements by their po_nbr value.

      <xsl:key name="ASNInPO-by-po_nbr" 
               match="ASNInPO" use="po_nbr"/>
    

    Then we’ll write a template which matches an ASNInDesc. We’ll make a
    copy of the element, along with its asn_nbr. Now we want to group
    the contained ASNInPO elements by their po_nbr. We do this by
    applying templates to the first ASNInPo in each group:

      <xsl:template match="ASNInDesc">
        <xsl:copy>
          <xsl:copy-of select="asn_nbr"/>
          <xsl:apply-templates select="ASNInPO[generate-id() =
                                       generate-id(key('ASNInPO-by-po_nbr', 
                                                       po_nbr)[1])]"/>
        </xsl:copy>
      </xsl:template>
    

    Grouping 2: ASNInCtn elements by container_id

    But before we go further, we’ll need to define another key. It seems
    like we need to group ASNInCtn elements by their container_id (see note below if this is not the case).

      <xsl:key name="ASNInCtn-by-container_id" 
               match="ASNInCtn" use="container_id"/>
    

    We’ll need that key in the following template which matches ASNInPO
    elements. Remember that the elements we process here will be the first
    ones of their group, since we selected only those in the
    xsl:apply-template above.

    This template is similar to the one we wrote above. We make copy of
    the element itself along with its po_nbr and then again apply
    templates to the first ASNInCtn elements grouped by their
    container_id:

      <xsl:template match="ASNInPO">
        <xsl:copy>
          <xsl:copy-of select="po_nbr"/>
          <xsl:apply-templates select="key('ASNInPO-by-po_nbr', po_nbr)/
                                       ASNInCtn[generate-id() =
                                       generate-id(key('ASNInCtn-by-container_id',
                                                       container_id)[1])]"/>
        </xsl:copy>
      </xsl:template>
    

    Finally, we write the template which matches ASNInCtn elements. This
    copies the element itself, and its container_id and then copies all
    ASNInItem elements in the same group:

      <xsl:template match="ASNInCtn">
        <xsl:copy>
          <xsl:copy-of select="container_id"/>
          <xsl:copy-of select="key('ASNInCtn-by-container_id', 
                                   container_id)/ASNInItem"/>
        </xsl:copy>
      </xsl:template>
    

    And we’re done.

    </xsl:stylesheet>
    

    Note

    The solution assumes that the ASNInCtn element with a given
    container_id can only appear within ASNInPO elements with the same
    po_nbr. If this is not the case, then you need to adjust the key for
    ASNInPO objects to use a combination of po_nbr and container_id.

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

Sidebar

Related Questions

the mysql table below has two columns. how do i select only those rows
How to separate below two plots into different pages ? command onefile is meant
Are the below two queries functionally the same? The first one doesn't return any
Are the below two pieces of code the same? String foo = foo; String
Below are two queries that return the same data. Other then style I am
I need a function that can return the difference between the below two dates
I am getting the following failure message when i build on the below two
I have four activities namely, Demo_tabActivity.java [main activity] Tabhost.java The below two activities are
I have four activities namely, Demo_tabActivity.java [main activity] Tabhost.java The below two activities are
Below are two programs that are almost identical except that I switched the i

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.