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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:18:51+00:00 2026-06-01T00:18:51+00:00

I met with an xml tranformation problem. After applying a suggested muenchian grouping to

  • 0

I met with an xml tranformation problem. After applying a suggested muenchian grouping to remove identical elements in a new xml, I could not convert multi tag elements from a source xml into each related group in a new xml. My source xml is like following:

<?xml version="1.0"?>
<InputShipmentSchedule xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<DataArea>
    <ShipmentSchedule>
        <ShipmentScheduleLine>
            <ManufacturingItem>
                <ItemID>
                    <ID>P313503</ID>
                </ItemID>
            </ManufacturingItem>
            <EffectiveTimePeriod>
                <StartDate>2012-03-08</StartDate>
            </EffectiveTimePeriod>
            <ItemQuantity unitCode="PC">3</ItemQuantity>                
        </ShipmentScheduleLine>
        <ShipmentScheduleLine>
            <ManufacturingItem>
                <ItemID>
                    <ID>P313503</ID>
                </ItemID>
            </ManufacturingItem>
            <EffectiveTimePeriod>
                <StartDate>2012-03-09</StartDate>
            </EffectiveTimePeriod>
            <ItemQuantity unitCode="PC">1</ItemQuantity>            
        </ShipmentScheduleLine>
        <ShipmentScheduleLine>
            <ManufacturingItem>
                <ItemID>
                    <ID>P313504</ID>
                </ItemID>
            </ManufacturingItem>
            <EffectiveTimePeriod>
                <StartDate>2012-03-08</StartDate>
            </EffectiveTimePeriod>
            <ItemQuantity unitCode="PC">10</ItemQuantity>           
        </ShipmentScheduleLine>
        <ShipmentScheduleLine>
            <ManufacturingItem>
                <ItemID>
                    <ID>P313504</ID>
                </ItemID>
            </ManufacturingItem>
            <EffectiveTimePeriod>
                <StartDate>2012-03-10</StartDate>
            </EffectiveTimePeriod>
            <ItemQuantity unitCode="PC">8</ItemQuantity>            
        </ShipmentScheduleLine>
    </ShipmentSchedule>
</DataArea>
</InputShipmentSchedule>

The following is my XSLT:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="*"/> <xsl:output indent="yes"/>

<xsl:key name="n" match="ItemID" use="ID"/>
<xsl:template match="/">
    <Output_Data>
        <ShipmentSchedule>
        <xsl:for-each select="//ManufacturingItem/ItemID[generate-id()=generate-id(key('n',.))]">
        <Part_Detail>
            <part_no value="{.}"/>
            <xsl:for-each select="//ManufacturingItem/ItemID[generate-id()=generate-id(key('n',.))]">
                <xsl:call-template name="requirement_detail_template"/>
            </xsl:for-each>
        </Part_Detail>
        </xsl:for-each>
        </ShipmentSchedule>
    </Output_Data>
</xsl:template>

<xsl:template name="requirement_detail_template">   
    <Requirement_Detail>
        <requirement_date value="{../../EffectiveTimePeriod/StartDate}"/>
        <requirement_qty value="{../../ItemQuantity}"/>
    </Requirement_Detail>
</xsl:template>
</xsl:stylesheet> 

What I am getting:

<?xml version="1.0" encoding="UTF-8"?>
<Output_Data>
<ShipmentSchedule>
<Part_Detail>
<part_no value="P313503"/>
<Requirement_Detail>
<requirement_date value="2012-03-08"/>
<requirement_qty value="3"/>
</Requirement_Detail>
<Requirement_Detail>
<requirement_date value="2012-03-08"/>
<requirement_qty value="10"/>
</Requirement_Detail>
</Part_Detail>
<Part_Detail>
<part_no value="P313504"/>
<Requirement_Detail>
<requirement_date value="2012-03-08"/>
<requirement_qty value="3"/>
</Requirement_Detail>
<Requirement_Detail>
<requirement_date value="2012-03-08"/>
<requirement_qty value="10"/>
</Requirement_Detail>
</Part_Detail>
</ShipmentSchedule>
</Output_Data>

What I expect should be:

<?xml version="1.0" encoding="UTF-8"?>
<Output_Data>
<ShipmentSchedule>
<Part_Detail>
<part_no value="P313503"/>
<Requirement_Detail>
<requirement_date value="2012-03-08"/>
<requirement_qty value="3"/>
</Requirement_Detail>
<Requirement_Detail>
<requirement_date value="2012-03-09"/>
<requirement_qty value="1"/>
</Requirement_Detail>
</Part_Detail>
<Part_Detail>
<part_no value="P313504"/>
<Requirement_Detail>
<requirement_date value="2012-03-08"/>
<requirement_qty value="10"/>
</Requirement_Detail>
<Requirement_Detail>
<requirement_date value="2012-03-10"/>
<requirement_qty value="8"/>
</Requirement_Detail>
</Part_Detail>
</ShipmentSchedule>
</Output_Data>

How should I set test conditions in the xsl:if? Can anyone help me to correct my XSLT for 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-01T00:18:53+00:00Added an answer on June 1, 2026 at 12:18 am

    change this part of your XSLT:

        <Part_Detail> 
           <part_no value="{.}"/>
           <xsl:for-each select="//ManufacturingItem/ItemID[generate-id()=generate-id(key('n',.))]">
             <xsl:call-template name="requirement_detail_template"/>
           </xsl:for-each>
        </Part_Detail> 
    

    to this:

        <Part_Detail>
           <xsl:variable name="part_no" select="."/>
           <part_no value="{$part_no}"/>
           <xsl:for-each select="//ManufacturingItem/ItemID[. = $part_no]">
             <xsl:call-template name="requirement_detail_template"/>
           </xsl:for-each>
        </Part_Detail>
    

    and you will get the desired result — the outer loop using “//ManufacturingItem/ItemID[generate-id()=generate-id(key(‘n’,.))]” is getting you a “distinct” list of part IDs by returning the FIRST occurrence of each distinct part number. If you use the same expression in your inner loop then you are just using that first occurrence repeatedly. Instead your inner for-each loop must look at each occurrence for each of those distinct part numbers

    Take care

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

Sidebar

Related Questions

I met a strange error after migration to XTEXT2. When I write three elements,
I have met a problem with virtualbox, I hope someone could help me here,
I'm new to image processing with Python and met a strange problem. For example
I met a problem which is very strange, my company uses Visual Source Safe
I met a problem when trying @Singleton of Guice: import com.google.inject.Singleton; @Singleton public class
I have a client whose requirement is best met with an XQuery/XML solution. The
i noticed strange problem in sdk 3.0. When i parse XML everything works fine
could not find anything on this, wondering if anyone knew about this or a
I met a problem while using python(2.6) cgi to show a mime data in
I have not met this type of grammar before. What does it mean? To

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.