RE: RE: [xsl] How to implement an array

Subject: RE: RE: [xsl] How to implement an array
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Mon, 10 Feb 2003 18:18:28 -0500
At 04:18 PM 2/10/2003, Charles wrote:
The output:
=========================================================
<table>
  <tr>
    <td></td>
    <td>Jan</td>
    <td>Feb</td>
    <td>Mar</td>
    <td>Apr</td>
    <td>May</td>
    <td>Jun</td>
    <td>Jul</td>
    <td>Aug</td>
    <td>Sep</td>
    <td>Oct</td>
    <td>Nov</td>
    <td>Dec</td>
  </tr>
  <tr>
    <td>A</td>
    <td sort="1" month="Jan">5</td>
    <td sort="2" month="Feb">10</td>
    <td sort="3" month="Mar">15</td>
    <td sort="4" month="Apr">20</td>
    <td sort="5" month="May">25</td>
    <td sort="6" month="Jun">30</td>
    <td sort="7" month="Jul">65</td>
    <td sort="8" month="Aug">70</td>
    <td sort="9" month="Sep">75</td>
    <td sort="10" month="Oct">80</td>
    <td sort="11" month="Nov">85</td>
    <td sort="12" month="Dec">90</td>
  </tr>
    <tr><td>B</td>
    <td sort="4" month="Apr">50</td>
    <td sort="5" month="May">55</td>
    <td sort="6" month="Jun">60</td>
    <td sort="10" month="Oct">35</td>
    <td sort="11" month="Nov">40</td>
    <td sort="12" month="Dec">45</td>
  </tr>
</table>


Generating a list of unique month names was easy to do using the <xsl:key> element and the key() function. I am stuck, probably at the same spot you are, at how to get empty <td> elements in the columns at the rows where there is no corresponding <col> element.

If you have a complete list of all the unique names allowable (not hard to do, if they're really the months :-), you can create a lookup table for reference. In this case, a simple list of the months will do. Iterate over the lookup table (it can be in your stylesheet, accessed as a node set with the document('') trick) and generate one <td> for each. If in the row you are working on, that month has an entry, populate it accordingly; otherwise just put a non-breaking space in there.


If the allowed values are not all known in advance, a two-pass solution, or a node-set extension function, can allow construction of this lookup table dynamically.

Sorry I can't show this in code! at the moment ...but "lookup table" in the FAQ should turn up something about this technique.

Cheers,
Wendell


====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================


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



Current Thread