xsl-list
[Top] [All Lists]

RE: Question on loops

2004-03-23 03:34:06
Hi,

<?xml version="1.0" encoding="UTF-8"?>
<DBInspector ReportName="Query Report" Date="15.01.2004">
      <SQLStatement>select * from testdb2.person p, 
testdb2.adresse a where 
p.persnr = a.persnr</SQLStatement>
      <ColumnNames>
              <Column>persnr</Column>
              <Column>name</Column>
              <Column>vorname</Column>
              <Column>nr</Column>
              ...
      </ColumnNames>
      <ColumnEntries>
              <Row>
                      <Entrie type="Integer">1</Entrie>
                      <Entrie type="Variable 
Character">Wehnert</Entrie>
                      <Entrie type="Variable 
Character">Lothar</Entrie>
                      <Entrie type="Variable Character">Yoyo</Entrie>
                      <Entrie type="Variable 
Character">Lothar</Entrie>
                      ...
              </Row>
              <Row>
                      <Entrie type="Integer">2</Entrie>
                      <Entrie type="Variable Character">Egg</Entrie>
                      <Entrie type="Variable Character">Loth</Entrie>
                      <Entrie type="Variable Character">Was</Entrie>
                      <Entrie type="Variable Character">Ertz</Entrie>
                      ...
              </Row>
              ...

My aim is to create a table after e.g. every second column.

Something like this:

persnr   name
----------------
1        Wehnert
2        Egg


vorname  nr
----------------
Yoyo     Lothar
Was      Ertz

Do you have an error in your example, because the third Entrie is always 
ignored and you only have four Columns? Anyhow, the approach still applies. 

  <xsl:template match="ColumnNames">
    <xsl:for-each select="Column[position() mod 2 = 1]">
      <xsl:variable name="position" select="position() * 2 - 1"/>
      <table>
        <thead>
          <tr>
            <th>
              <xsl:value-of select="."/>
            </th>
            <th>
              <xsl:value-of select="following-sibling::Column[1]"/>
            </th>
          </tr>
        </thead>
        <tbody>
          <xsl:value-of select="$position"/>
          <xsl:for-each select="../../ColumnEntries/Row/Entrie[position() = 
$position]">
            <tr>
              <td>
                <xsl:value-of select="."/>
              </td>
              <td>
                <xsl:value-of select="following-sibling::Entrie[1]"/>
              </td>
            </tr>
          </xsl:for-each>
        </tbody>
      </table>
    </xsl:for-each>
  </xsl:template>

Cheers,

Jarno - neuroticfish: wakemeup! (club-edit)


<Prev in Thread] Current Thread [Next in Thread>
  • RE: Question on loops, Jarno.Elovirta <=