[xsl] Building an index in XSL

Subject: [xsl] Building an index in XSL
From: Chris Gow <cgow@xxxxxxxxxxxxxxxxxx>
Date: Wed, 14 Feb 2001 15:44:23 -0500

Hi All:

I need to build an index in an XSL stylesheet that has a variable number of entry groupings ( numbers, a-e, f-i, etc..). Each grouping will appear in its own HTML table, however, if there are no entries that belong to that grouping ( nothing starts with a, b, c, d or e) I do not want the grouping or even the table to appear/be created. 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. Below is a sample XML and XSL based on what I am trying to accomplish (sorry for the large email).

Perhaps the way I set it up is not the best way to approach what I need, if anybody has an tips or pointers that would be cool, however, please note that I would like to keep the <entry-groupings/> inside the XML (I include that dynamically using Cocoon and like the fact that I can change my groupings).

Thanks in advance


=======BEGIN XML=======
<grouping name="#">
<!-- and so forth for 3 - 0-->
<grouping name="a-e">
<!-- this would continue for b - e, both upper and lower case letters -->
<!-- I would have other grouping groupings for f - h and so forth (not shown here) -->

<category name="Bogus">
<product name="A foo"/>
<product name="Bar"/>
<category name="Stuff that isn't good for you but tastes good, well sort of">
<product name="3 Musketeers"/>

    <category name="Ice rink stuff">
      <product name="Zamboni"/>
    <!-- potentially more categories with products -->
=======BEGIN XSL======
<!--stylesheet, standard templates not shown -->

<xsl:template match="page">
  <!-- bunch of stuff to set up the page not included-->
  <xsl:apply-templates select="/page/entry-groupings/grouping"/>
   <!-- bunch HTML stuff to finish off the page not included -->

<xsl:template match="group">
<!-- I need to do some test here that would see if any product in any of the categories start with a letter (case irrelevant) in the current group. The way it is currently implemented I can't :(-->
<table border="1" width="100%">
<tr><td colspan="2" bgcolor="#AAAAAA"><a name="{@name}"><b><xsl:value-of select="@name"/></b></a></td></tr>

<xsl:template match="entry-groupings/grouping/entry">
<!--The matching template for product is not included (it just displays it in a table) -->
<xsl:apply-templates select="/page/content/category/product[substring(@name,1,1)=current()]"/>

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

Current Thread