This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: Building an index in XSL


> I have a partial solution implemented but I can not figure out 
> how to not create the HTML table or grouping if no matches are 
> found.  

Keys will help you a lot. I recently implemented something similar to this
in my project.  I didn't put my solution in <table> format, but that should
be trivial to do.

I hope this will help you out.

Regards,
Kurt

---

<!-- Key for the grouping -->
<xsl:key name="indexindex" match="product"
use="translate(substring(@name,1,1),'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJ
KLMNOPQRSTUVWXYZ')" />

<!-- Key for the product -->
<xsl:key name="indexreference" match="product" use="@name" />

<xsl:template match="grouping" mode="index" >
	<!-- Table "grouping" heading -->
	<xsl:value-of select="@name" />
	<xsl:for-each select="entry">
		<xsl:call-template name="output-index-by-letter">
			<xsl:with-param name="letter"
select="substring(entry,1,1)" />
		</xsl:call-template>
	</xsl:for-each>
</xsl:template>

<xsl:template name="output-index-by-letter">
	<xsl:param name="letter" select="'1'" />
	<xsl:for-each select="key('indexindex',$letter)">
		<xsl:sort select="@name" />
		
		<!-- If this is the first entry, then output the heading -->
		<xsl:if test="position()=1">
			<p class="indexhead"><xsl:value-of select="$letter"
/></p>
		</xsl:if>
				
		<!-- If this is the first time the entry appears, then
output it -->
		<xsl:if test="generate-id() =
generate-id(key('indexreference',@name)[1])">
			<p class="indexentry"><xsl:value-of select="@name"
/></p>
		</xsl:if>
	</xsl:for-each>
</xsl:template>

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]