So I have this data for a client ( see below ) and I want to create a bulleted list that can have any number of tiers. I also want it to be dynamic in the aspect that items can be listed more than once. The CMS is set up so a TAG will claim its parents. Wherever a TAG claims its parents, its children should replicate beneath. Not sure how to tackle this with XSLT, but a simple example should end up looking something like this..
<ul>
<li>Missions</li>
<li>
<ul>
<li>Kampala, Uganda</li>
<li>Lima, Peru</li>
</ul>
</li>
</ul>
If Kampala, Uganda also claimed something else as a parent, it would appear multiple times. If Kampala, Uganda had other TAGS that claimed it as a parent, these children would cascade beneath Kampala, Uganda in each instance.
<data>
<tags>
<section id="3" handle="tags">Tags</section>
<entry id="72">
<parents>
<item handle="meetings">Meetings</item>
</parents>
<tag handle="bible-studies">Bible studies</tag>
</entry>
<entry id="51">
<parents>
<item handle="missions">Missions</item>
</parents>
<tag handle="brazil">Brazil</tag>
</entry>
<entry id="31">
<parents>
<item handle="ministry">Ministry</item>
</parents>
<tag handle="childrens-ministry">Children's ministry</tag>
</entry>
<entry id="28">
<parents>
<item handle="ministry">Ministry</item>
</parents>
<tag handle="college-and-career-ministry">College and Career ministry</tag>
</entry>
<entry id="56">
<parents>
<item handle="the-islands-of-vanuatu">The Islands of Vanuatu</item>
</parents>
<tag handle="fanafo-christian-fellowship">Fanafo Christian Fellowship</tag>
</entry>
<entry id="29">
<parents>
<item handle="ministry">Ministry</item>
</parents>
<tag handle="high-school-ministry">High School ministry</tag>
</entry>
<entry id="48">
<parents>
<item handle="missions">Missions</item>
</parents>
<tag handle="holsbybrunn-sweden">Holsbybrunn, Sweden</tag>
</entry>
<entry id="22">
<tag handle="home">Home</tag>
</entry>
<entry id="19">
<tag handle="israel">Israel</tag>
</entry>
<entry id="30">
<parents>
<item handle="ministry">Ministry</item>
</parents>
<tag handle="junior-high-ministry">Junior High ministry</tag>
</entry>
<entry id="47">
<parents>
<item handle="missions">Missions</item>
</parents>
<tag handle="kampala-uganda">Kampala, Uganda</tag>
</entry>
<entry id="49">
<parents>
<item handle="missions">Missions</item>
</parents>
<tag handle="lima-peru">Lima, Peru</tag>
</entry>
<entry id="64">
<parents>
<item handle="" />
</parents>
<tag handle="meetings">Meetings</tag>
</entry>
<entry id="32">
<parents>
<item handle="ministry">Ministry</item>
</parents>
<tag handle="men-s-ministry">Men’s ministry</tag>
</entry>
<entry id="44">
<parents>
<item handle="" />
</parents>
<tag handle="ministry">Ministry</tag>
</entry>
<entry id="33">
<tag handle="missions">Missions</tag>
</entry>
<entry id="54">
<parents>
<item handle="the-islands-of-vanuatu">The Islands of Vanuatu</item>
</parents>
<tag handle="natanara-christian-fellowship">Natanara Christian Fellowship</tag>
</entry>
<entry id="50">
<parents>
<item handle="missions">Missions</item>
</parents>
<tag handle="ouagadougou-burkina-faso">Ouagadougou, Burkina Faso</tag>
</entry>
<entry id="46">
<parents>
<item handle="missions">Missions</item>
</parents>
<tag handle="the-islands-of-vanuatu">The Islands of Vanuatu</tag>
</entry>
<entry id="77">
<parents>
<item handle="missions">Missions</item>
</parents>
<tag handle="villahermosa-mexico">Villahermosa, Mexico</tag>
</entry>
<entry id="27">
<parents>
<item handle="ministry">Ministry</item>
</parents>
<tag handle="womens-ministry">Women's ministry</tag>
</entry>
<entry id="73">
<parents>
<item handle="meetings">Meetings</item>
</parents>
<tag handle="worship">Worship</tag>
</entry>
</tags>
I don't think you need the children of an item to be wrapped in another
<li>.This transformation (quite similar to that of @Alejandro, but simpler, shorter and not requiring any parameters at all):
when applied on the referred to source XML document:
produces the wanted, correct result:
Do note: This solution works correctly when a
taghas more than one parent.Explanation:
<xsl:key name="kChildren" match="tag"use="string(../parents/item/@handle)"/>produces all the "children" from the string value of the
handleattribute of the first (only)itemchild of theirparentssibling. This covers also suchtagelements that don't have anyparentssibling (in which case the key value is the empty string)..2. A second key with the same name:
matches a
tagby the value of anyhandleattribute of theitemchild of theirparentssibling. This makes it possible to have thetaglisted for all "parents", not only for the first.As we see here, the ability to have multiple keys with the same name is a very powerful and useful feature.