This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Seeking help on Grouping distingt sub-elements


I apologize if this has been answered - I've searched archives, etc and have found some similar threads, but nothing that I've been able to turn into success and I'm at the end of my (limited!) XSL rope...

Below is the input XML that I'm starting with.  The goal is for all of the chassis in a shipment (in a company, in an order), where the chassis have the same <commonid> value, combine those chassis into one chassis element, where that chassis element has the 'common' elements of each of the matching chassis (<commonid> and <commonelement>) and to then add a new tag that enumerates each of the specific <specificelement> elements from the group.  Note that one twist on this is that the <commonelement> element can have a different value in each <chassis> group member and that the last <commonelement> encountered for a group of <chassis> elements (in the same <shipment>) with the same <commonid> is the one that 'wins' - ie, is written to the output document - also note that the values don't determine which one 'wins' - I just used 1's and 2's for illustrative purposes - its the position (ie, last encountered in the group) that matters.

Below this is the output XML - ie, that which I'm trying to get to.

>>Input XML<<
<order>
        <company>
                <name>company1</name>
                <shipment>
                        <shiptoid>1</shiptoid>
                        <chassis>
                                <commonid>19</commonid>
                                <commonelement>c191</commonelement>
                                <specificelement>s191</specificelement>
                        </chassis>
                        <chassis>
                                <commonid>17</commonid>
                                <commonelement>c171</commonelement>
                                <specificelement>s171</specificelement>
                        </chassis>
                        <chassis>
                                <commonid>19</commonid>
                                <commonelement>c192</commonelement>
                                <specificelement>s192</specificelement>
                        </chassis>
                        <chassis>
                                <commonid>17</commonid>
                                <commonelement>c172</commonelement>
                                <specificelement>s172</specificelement>
                        </chassis>
                </shipment>
                <shipment>
                        <shiptoid>2</shiptoid>
                        <chassis>
                                <commonid>18</commonid>
                                <commonelement>c181</commonelement>
                                <specificelement>s181</specificelement>
                        </chassis>
                        <chassis>
                                <commonid>16</commonid>
                                <commonelement>c161</commonelement>
                                <specificelement>s161</specificelement>
                        </chassis>
                        <chassis>
                                <commonid>18</commonid>
                                <commonelement>c182</commonelement>
                                <specificelement>s182</specificelement>
                        </chassis>
                        <chassis>
                                <commonid>16</commonid>
                                <commonelement>c162</commonelement>
                                <specificelement>s162</specificelement>
                        </chassis>
                </shipment>
        </company>
        <company>
                <name>company2</name>
                <shipment>
                        <shiptoid>3</shiptoid>
                        <chassis>
                                <commonid>29</commonid>
                                <commonelement>c291</commonelement>
                                <specificelement>s291</specificelement>
                        </chassis>
                        <chassis>
                                <commonid>27</commonid>
                                <commonelement>c271</commonelement>
                                <specificelement>s271</specificelement>
                        </chassis>
                        <chassis>
                                <commonid>29</commonid>
                                <commonelement>c292</commonelement>
                                <specificelement>s292</specificelement>
                        </chassis>
                        <chassis>
                                <commonid>27</commonid>
                                <commonelement>c271</commonelement>
                                <specificelement>s271</specificelement>
                        </chassis>
                </shipment>
                <shipment>
                        <shiptoid>4</shiptoid>
                        <chassis>
                                <commonid>28</commonid>
                                <commonelement>c281</commonelement>
                                <specificelement>s281</specificelement>
                        </chassis>
                        <chassis>
                                <commonid>26</commonid>
                                <commonelement>c261</commonelement>
                                <specificelement>s261</specificelement>
                        </chassis>
                        <chassis>
                                <commonid>28</commonid>
                                <commonelement>c282</commonelement>
                                <specificelement>s282</specificelement>
                        </chassis>
                        <chassis>
                                <commonid>26</commonid>
                                <commonelement>c262</commonelement>
                                <specificelement>s262</specificelement>
                        </chassis>
                </shipment>
        </company>
</order>

>>Output XML<<
<order>
        <company>
                <name>company1</name>
                <shipment>
                        <shiptoid>1</shiptoid>
                        <chassis>
                                <commonid>19</commonid>
                                <commonelement>c192</commonelement>  <!--note that the 'last one wins' for the commonelement-->
                                <newtag>
                                        <specificelement>s191</specificelement>
                                        <specificelement>s192</specificelement>
                                </newtag>
                        </chassis>
                        <chassis>
                                <commonid>17</commonid>
                                <commonelement>c172</commonelement>
                                <newtag>
                                        <specificelement>s171</specificelement>
                                        <specificelement>s172</specificelement>
                                </newtag>
                        </chassis>
                </shipment>
                <shipment>
                        <shiptoid>2</shiptoid>
                        <chassis>
                                <commonid>18</commonid>
                                <commonelement>c182</commonelement>
                                <newtag>
                                        <specificelement>s181</specificelement>
                                        <specificelement>s182</specificelement>
                                </newtag>
                        </chassis>
                        <chassis>
                                <commonid>16</commonid>
                                <commonelement>c162</commonelement>
                                <newtag>
                                        <specificelement>s161</specificelement>
                                        <specificelement>s162</specificelement>
                                </newtag>
                        </chassis>
                </shipment>
        </company>
        <company>
                <name>company2</name>
                <shipment>
                        <shiptoid>3</shiptoid>
                        <chassis>
                                <commonid>29</commonid>
                                <commonelement>c292</commonelement>
                                <newtag>
                                        <specificelement>s291</specificelement>
                                        <specificelement>s292</specificelement>
                                </newtag>
                        </chassis>
                        <chassis>
                                <commonid>27</commonid>
                                <commonelement>c272</commonelement>
                                <newtag>
                                        <specificelement>s271</specificelement>
                                        <specificelement>s272</specificelement>
                                </newtag>
                        </chassis>
                </shipment>
                <shipment>
                        <shiptoid>4</shiptoid>
                        <chassis>
                                <commonid>28</commonid>
                                <commonelement>c282</commonelement>
                                <newtag>
                                        <specificelement>s281</specificelement>
                                        <specificelement>s282</specificelement>
                                </newtag>
                        </chassis>
                        <chassis>
                                <commonid>26</commonid>
                                <commonelement>c262</commonelement>
                                <newtag>
                                        <specificelement>s261</specificelement>
                                        <specificelement>s262</specificelement>
                                </newtag>
                        </chassis>
                </shipment>
        </company>
</order>

I have tried various implemenations of 'Meunchian' groupings, but can't get it to work - the best I get is all <commonid> elements grouped in a single group (regardless of company, shipment, etc) and w/o the <commonelement> item being addressed at all.  I've hacked up most of the classic grouping examples (Projects/PROWOW, wierd_doc/System, Authors/Titles, etc) as well, but all to no avail.

Any help is VERY much appreciated!!  In the end, I think its coming down to a lack of sufficient understanding of the <xsl:key> tag on my part.

Thanks,

Jim Stoll



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]