In continuation of the question I had asked concerning "How to create subsets of a single set of elements with XSLT?"
I wish to take my problem one step further: I had originally given the following XML as the original:
<Set>
<Element name="Superset1_Set1_Element1"/>
<Element name="Superset1_Set1_Element2"/>
<Element name="Superset1_Set2_Element1"/>
<Element name="Superset2_Set1_Element1"/>
<Element name="Superset2_Set2_Element1"/>
</Set>
And had asked for the XSL Transformation to produce the following output:
<Superset name="Superset1">
<Set name="Set1">
<Element name="Element1"/>
<Element name="Element2"/>
</Set>
<Set name="Set2">
<Element name="Element1"/>
</Set>
</Superset>
<Superset name="Superset2">
<Set name="Set1">
<Element name="Element1"/>
</Set>
<Set name="Set2">
<Element name="Element1"/>
</Set>
</Superset>
Both Tomalak and annakata had given me a working solution. I had chosen Tomalak's due to it's use of templates which is, in my opinion more human readable.
The problem is that my XML is actually of the form:
<Set>
<Element name="Classic_Authors_Dante_Alighieri_The_Divine_Comedy"/>
<Element name="Classic_Authors_Dante_Alighieri_Convivio"/>
<Element name="Classic_Authors_Miguel_de_Cervantes_Saavedra_Don_Quixote"/>
<Element name="Contemporary_Authors_Stephen_King_Just_After_Sunset"/>
<Element name="Contemporary_Authors_Stephen_King_Desperation"/>
</Set>
Supersets, sets and elements have varying amounts of underscores within them. In the example above There are two supersets: 'Classic_Authors' and 'Contemporary_Authors'. The three sets are 'Dante_Alighieri', 'Miguel_de_Cervantes_Saavedra' and 'Stephen_King'.
The output XML should then be:
<Superset name="Classic_Authors">
<Set name="Dante_Alighieri">
<Element name="The_Divine_Comedy"/>
<Element name="Convivio"/>
</Set>
<Set name="Miguel_de_Cervantes_Saavedra">
<Element name="Don_Quixote"/>
</Set>
</Superset>
<Superset name="Contemporary_Authors">
<Set name="Stephen_King">
<Element name="Just_After_Sunset"/>
<Element name="Desperation"/>
</Set>
</Superset>
How then, can I use Tomalak's solution? That is, how should I prepare my xml to use his algorithm? Can it be done in a single XSLT? Might there be another solution?
Thanks all very much!