Re: [xsl] From one xml put the data into 3 columns. Please help me

Subject: Re: [xsl] From one xml put the data into 3 columns. Please help me
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Mon, 8 Mar 2004 09:55:37 +0000
Hi Dionisio,

> y have the bellow xml file and i want to put the data, the
> paginas_titulo node in 3 columns:
[snip]
> if there are 5 nodes (paginas_titulo nodes) apears one row with 3
> columns with data and other row with 2 columns with data and the
> other without data.

The first task is to select one sn_masterinformacion element to
represent each row, so that you generate the correct number of rows.
The first sn_masterinformacion elements in each row are numbered 1, 4,
7 etc. You can select them by looking at the remainder after dividing
by 3, using:

  sn_masterinformacion[position() mod 3 = 1]

These sn_masterinformacion elements give the content for the first
cell in each row. The next two sn_masterinformacion elements give the
content for the following cells, if there are any. Since you just want
the <td> to be empty in this case, the easiest thing is to create the
cells and use the content from the next two following sibling
sn_masterinformacion elements in them.

Something like:

  <xsl:for-each select="sn_masterinformacion[position() mod 3 = 1]">
    <tr>
      <td><xsl:apply-templates select="." /></td>
      <td>
        <xsl:apply-templates
          select="following-sibling::sn_masterinformacion[1]" />
      </td>
      <td>
        <xsl:apply-templates
          select="following-sibling::sn_masterinformacion[2]" />
      </td>
    </tr>
  </xsl:for-each>

with a template for the sn_masterinformacion element just giving the
value of the appropriate paginas_titulo element it contains:

<xsl:template match="sn_masterinformacion">
  <xsl:value-of select="paginas/sn_paginas/paginas_titulo" />
</xsl:template>

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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


Current Thread