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

RE: creating html tables from cells

Subject: RE: creating html tables from cells
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 15 Oct 2003 17:18:57 -0400
types of html tables
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 [@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[@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[@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[@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[@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@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

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.