xsl-list
[Top] [All Lists]

combining the children of similar nodes under one node

2004-03-06 17:12:18
in the following example code, notice that all three nodes have the same name. I want to combine all nodes with the same name into one node with all of their <style>s and <types>s, where <style> and <type> are not duplicated.

<inventory>
        <product>
                <name>chair</name>
                <style>rocking</style>
        </product>

        <product>
                <name>chair</name>
                <type>rocking</type> --> same value as <style> above
        </product>
        <product>
                <name>chair</name>
                <style>folding</style>
                <type>lawn</type>
        </product>
</inventory>

When I'm in the first node, I grab it, when I'm in the second node, I can check the preceding <style> value and skip it, when I'm in the third node I grab it. That gives me:

        <product>
                <name>chair</name>
                <style>rocking</style>
        </product>
        <product>
                <name>chair</name>
                <style>folding</style>
                <type>lawn</type>
        </product>

I figured out that, while in the second of these nodes, I can check if the preceding name is the same and, if so, get the preceding <style> and add it to the second product node, giving me:

        <product>
                <name>chair</name>
                <style>rocking</style>
        </product>
        <product>
                <name>chair</name>
                <style>rocking</style>
                <style>folding</style>
                <type>lawn</type>
        </product>

but I still have 2 products with the name "chair". how can I get the result:

        <product>
                <name>chair</name>
                <style>rocking</style>
                <style>folding</style>
                <type>lawn</type>
        </product>

One of the problems is that <style> and <type> are being used interchangeably, but I think I compensated for that. My big problem is getting everything listed under one name with no duplicates.

-dave




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



<Prev in Thread] Current Thread [Next in Thread>