[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Building an index in XSL

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


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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.