xsl-list
[Top] [All Lists]

RE: creating html tables from cells

2003-10-15 14:18:57
Dan,

At 04:45 PM 10/15/2003, you wrote:
<xsl:key name="ri-types" match="RI" use="@col" />

Allows you to retrieve RI elements by their @col values: okay.

<xsl:variable name="ri-types" select="/RS/RI[generate-id() =
generate-id(key('ri-types', @col)[1])]/@col" />

Binds a node-set to the variable "ri-types". The nodes are the collected @col attributes of RI elements that are the first RIs with their @col value.

<xsl:template match="/RS">
  <table>
  <xsl:variable name="content" select="RI"/>
  <xsl:for-each select="RI [(_at_)col='1']">
      <tr>
        <xsl:for-each select="$ri-types">

iterates over $ri-types for every first RI. But $ri-types will be the same every time. This is a problem.

          <td>
            <xsl:value-of select="$content[(_at_)col=current()]"/>

writes the string value of the first node in $content (all your RI elements) whose @col is the same as this RI/@col (which is always 1).

This accounts for why your output is so ... regular. :->

          </td>
        </xsl:for-each>
      </tr>
  </xsl:for-each>
  </table>
</xsl:template>

Instead, try

<xsl:key name="RIs-by-first-RI" match="RI" use="generate-id(preceding-sibling::RI[(_at_)col=1][1])"/>
<!-- retrieves RI elements by the generated ID of the first preceding RI with
     @col = 1 -->

<xsl:template match="RS">
  <table>
  <xsl:for-each select="RI[(_at_)col=1]">
      <!-- create a row -->
      <tr>
        <!-- create a cell for this RI -->
        <td>
          <xsl:apply-templates/>
        </td>
        <!-- now, create cells for all the RIs that come after this one
             but not after another RI[(_at_)col=1] -->
       <xsl:for-each select="key('RIs-by-first-RI',generate-id())">
          <td>
            <xsl:apply-templates"/>
          </td>
        </xsl:for-each>
      </tr>
  </xsl:for-each>
  </table>
</xsl:template>

Does that help? There are many ways to achieve this, but you started using keys, so I kept on....

Cheers,
Wendell



======================================================================
Wendell Piez                            
mailto:wapiez(_at_)mulberrytech(_dot_)com
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



<Prev in Thread] Current Thread [Next in Thread>