This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: two columns in a table from one


Hi Matt,

I had a simular problem which I asked on this list quite a while ago now.

(Thanks to Jeni who gave me a template for creating muli-column tables).

The example below is the one I used for a three column table...

<xsl:template name="threecolumns">
<!-- this sorts the currencies into three columns -->
  <xsl:for-each select="people[position() mod 3 = 1]">
    <tr>
    <xsl:variable name="others" select="following-sibling::option[position()
&lt; 3]" />
      <xsl:for-each select=".|$others">
        <td>
          <xsl:value-of select="person' />
        </td>
      </xsl:for-each>
      <xsl:if test="count($others) &lt; 2">
        <td></td>
          <xsl:if test="not($others)">
            <td></td>
          </xsl:if>
      </xsl:if>
    </tr>
  </xsl:for-each>
<!-- end of sorting the currencies into three columns -->
</xsl:template>



The following would do the two column display you are after (however I have
checked it for typos etc.)

<xsl:template name="twocolumns">
  <xsl:for-each select="people[position() mod 2 = 1]">
    <tr>
    <xsl:variable name="others" select="following-sibling::option[position()
&lt; 2]" />
      <xsl:for-each select=".|$others">
        <td>
          <xsl:value-of select="person' />
        </td>
        <xsl:if test="not($others)">
          <td></td>
        </xsl:if>
      </xsl:if>
    </tr>
  </xsl:for-each>
<!-- end of sorting the currencies into two columns -->
</xsl:template>

Cheers,

Tim Watts :)


-----Original Message-----
From: Matthew Smith

How can I turn a list of like named nodes into a two column html table with
xslt?
Here's some sample xml and desired html:

<!-- XML -->
<people>
  <person>John</person>
  <person>Suzy</person>
</people>

<!-- HTML -->
<table>
  <tr><td>John</td><td>Suzy</td></tr>
</table>

The empty td element in the final row of odd numbered lists isn't
imperative, but would be nice.
Thanks, Matt


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]