[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


Chris

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


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


    <category name="Ice rink stuff">
      <product name="Zamboni"/>
    </category>
    <!-- potentially more categories with products -->
</content>
</page>
=======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>

<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:apply-templates/>
</table>
<br/>
</xsl:template>


<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:template>



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



Current Thread