0

This is the input xml. I want to group by store(Id) = RS0001035 as in the xml using XSLT 1 version. Though in this example, store(Id) = same throughout the the payload provided below but it can be different input from time to time.

<storeInfo>
    <store_list>
       <r_store>
          <f>
              <store>RS0001035</store>
           </f>
        </r_store>
       <r_qty>
         <d>
            <f>
                 <qty_OnHand>1</qty_OnHand>
                 <qty_MinMax>2</qty_MinMax>
              </f>
           </d>
        </r_qty>
       <r_part>
         <d>
            <f>
                 <part>0000003AB</part>
                 <part_sub>0000003BC</part_sub>
              </f>
           </d>
        </r_part>
     </store_list>
    <store_list>
      <r_store>
        <f>
              <store>RS0001035</store>
           </f>
        </r_store>
      <r_qty>
         <d>
            <f>
                 <qty_OnHand>0</qty_OnHand>
                 <qty_MinMax>3</qty_MinMax>
              </f>
           </d>
        </r_qty>
       <r_part>
         <d>
            <f>
                 <part>0000003CD</part>
                 <part_sub>0000003EF</part_sub>
              </f>
           </d>
        </r_part>
     </store_list>
   <store_list>
      <r_store>
         <f>
              <store>RS0001035</store>
           </f>
        </r_store>
        <r_qty>
         <d>
            <f>
                 <qty_OnHand>3</qty_OnHand>
                 <qty_MinMax>3</qty_MinMax>
              </f>
           </d>
        </r_qty>
       <r_part>
         <d>
            <f>
                 <part>0000003GH</part>
                 <part_sub>0000003IJ</part_sub>
              </f>
           </d>
        </r_part>
     </store_list>
  </storeInfo>

The output will look like this. The output will be grouped by store(Id) : RS0001035. Then the store_list will show up store_list with part and quantity information rolled under the store(Id): RS0001035.

 <storeInfo>
    <store>RS0001035</store>
    <store_list>
       <part>0000003AB</part>
       <part_sub>0000003BC</part_sub>
       <qty_OnHand>1</qty_OnHand>
       <qty_MinMax>2</qty_MinMax>
     </store_list>
        <store_list>
       <part>0000003AB</part>
       <part_sub>0000003BC</part_sub>
       <qty_OnHand>0</qty_OnHand>
       <qty_MinMax>3</qty_MinMax>
     </store_list>
      <store_list>
       <part>0000003AB</part>
       <part_sub>0000003BC</part_sub>
       <qty_OnHand>3</qty_OnHand>
       <qty_MinMax>3</qty_MinMax>
     </store_list>
 </storeInfo>

I am not that great at XSLT as I am a beginner. Here is my code.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<storeInfo>
<xsl:for-each select="/storeInfo/store_list">
<store>
<xsl:value-of   select="."/>
</store>
</xsl:for-each>
<xsl:for-each select="/storeInfo/store_list">
<store_list>
<part>
<xsl:value-of   select="./r_part/d/f/part"/>
</part>
<part_sub>
<xsl:value-of   select="./r_part/d/f/part_sub"/>
</part_sub>
<qty_OnHand>
<xsl:value-of   select="./r_qty/d/f/qty_OnHand"/>
</qty_OnHand>
<qty_MinMax>
<xsl:value-of   select="./r_qty/d/f/qty_MinMax"/>
</qty_MinMax>
</store_list>
</xsl:for-each>
</storeInfo>
</xsl:template>
</xsl:stylesheet>
3
  • 1. Your input has only one store, so no actual grouping seems to be necessary - just a simple restructure. Please confirm. 2. Where exactly are you stuck with this? Post your attempt so we can fix it, instead of having to write your code for you from scratch. Commented Feb 15, 2024 at 1:06
  • @michael.hor257k Thanks for your inputs. I just updated. Commented Feb 15, 2024 at 1:17
  • If you really need to group by store, then start here: jenitennison.com/xslt/grouping/muenchian.html Commented Feb 15, 2024 at 2:10

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.