Saturday, June 11, 2011

Preceding-Sibling | The Easy Way

Keeping on track with my previous post regarding the preceding-sibling approach to getting unique values with XSL, I prefer to not have to do the Muench method whenever possible. I like to keep it simple. Here is a really simple way to get a unique or distinct list of categories and sub-categories from an xml file:




<xsl:for-each select="item">
<xsl:variable name="thisNodeCategory" select="Category"/>
<xsl:if test="not(preceding-sibling::item[Category=$thisNodeCategory])">
<span class="Category">
<a href="">
<xsl:value-of select="Category" />
</a>
</span>
<br/>
</xsl:if>
<xsl:if test="SubCategory > ''">
<span class="subCategory">
- <a href="">
<xsl:value-of select="SubCategory" />subcategory
</a>
</span>
<br/>
</xsl:if>
</xsl:for-each>

1 comment:

  1. What do you think about xsl fo editor?? Thank you for this post by the way! Very helpful!

    ReplyDelete