Forum Moderators: open
<inventory>
<item name="Standard Sword" equipped="true" type="weapon" ammount="1"/>
<item name="Backpack" equipped="true" type="container" ammount="1">
<!-- now the fun part starts -->
<item name="Healing Potion (60)" type="potion" ammount="7"/>
<item name="Clothe bag" type="container" ammount="1">
<item name="Azurite (200gp)" type="gem" ammount="2"/>
<item name="Gold piece" type="money" ammount="48"/>
</item><!-- Clothe bag-->
</item><!-- Backpack-->
</inventory> <ul class="inventory">
<li class="equipped"><img src="weapon.gif"/>Standard Sword</strong></li>
<li class="equipped"><img src="container.gif"/>Backpack</strong><ul>
<li><img src="potion.gif"/>7 × Healing Potion (60)</li>
<li><img src="container.gif"/>Clothe bag<ul>
<li><img src="gem.gif"/>2 × Azurite (200gp)</li>
<li><img src="money.gif"/>48 × Gold piece</li>
</ul><!-- this closes the Clothe bag list-->
</ul><!-- this closes the Backpack list-->
</ul><!-- this closes the initial list--> Thanks for your attention, and greetings.
Herenvardö, Happy Hippie Heviatta (a.k.a. H4)
[edited by: Herenvardo at 8:51 pm (utc) on Nov. 24, 2006]
At the end of your template, add an <xsl:apply-templates /> directive to instruct the processor to repeat the match, but on the current node set (i.e. first it passes through inventory/item s, then it will pass through the inventory/item/item s. ).
Your code has extraneous </strong> tags which I'll conveniently ignore. Here's a quick-and-dirty set of templates that will generate the output you're after:
<!-- create an unordered list with the class attribute value of "inventory" for each "inventory" element -->
<xsl:template match="inventory">
<ul class="inventory"><!-- process the "item" child elements of inventory -->
<xsl:apply-templates select="item" /></ul>
</xsl:template><xsl:template match="item">
<!-- create a list item for every "item" element --><li>
<!-- does the "item" have an "equipped" attribute whose value is true? if so, create a class attribute on the li with the value "equipped" --><xsl:if test="@equipped='true'">
<xsl:attribute name="class">equipped</xsl:attribute>
</xsl:if><!-- does the "item" have a "type" attribute whose value is not null? if so, insert the value of "type" in the src attribute of the img -->
<xsl:if test="@type!= ''">
<img src="{@type}.gif" /><!-- does the "item" have an "ammount" attribute whose value is greater than one? if so, insert the value of "ammount" and some text -->
<xsl:if test="@ammount > 1">
<xsl:value-of select="@ammount" />
<xsl:text> × </xsl:text>
</xsl:if>
</xsl:if><!-- insert the "name" of the "item" -->
<xsl:value-of select="@name" />
<xsl:if test="item">
<!-- if the "item" has child items, create a new list and start over again --><ul>
<xsl:apply-templates />
</ul>
</xsl:if></li>
</xsl:template>