Re: [xsl] how to view data in tabuler view

Subject: Re: [xsl] how to view data in tabuler view
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 31 Oct 2002 12:52:39 +0000
Hi Mohamed,

> the above data must view in tabuler form, which caption is the
> titles or table header , and the values are table body.
>
> my first question is how to put all captions as titles which the
> caption repeat every row and i want to get it once only,and put each
> related data under its title

When you create the table header, only iterate over the captions in
the *first* row of your source; when you create the table body,
iterate over *all* the rows and only look at the amount under each
item:

<xsl:template match="document">
  <table>
    <thead>
      <tr>
        <xsl:for-each select="row[1]/item">
          <th><xsl:value-of select="caption" /></th>
        </xsl:for-each>
      </tr>
    </thead>
    <tbody>
      <xsl:for-each select="row">
        <tr>
          <xsl:for-each select="item">
            <td><xsl:value-of select="amount" /></td>
          </xsl:for-each>
        </tr>
      </xsl:for-each>
    </tbody>
  </table>
</xsl:template>

> second how to put currency value beside price without currency
> caption.

Only iterate over those items whose caption is not 'currency'; when
you're processing an item whose caption is 'Unit Price' then include
the <amount> for the <item> in the same <row> whose caption is
'currency':

<xsl:template match="document">
  <table>
    <thead>
      <tr>
        <xsl:for-each select="row[1]/item[caption != 'currency']">
          <th><xsl:value-of select="caption" /></th>
        </xsl:for-each>
      </tr>
    </thead>
    <tbody>
      <xsl:for-each select="row">
        <tr>
          <xsl:for-each select="item[caption != 'currency']">
            <td>
              <xsl:value-of select="amount" />
              <xsl:if test="caption = 'Unit Price'">
                <xsl:value-of
                  select="../item[caption = 'currency']/amount" />
              </xsl:if>
            </td>
          </xsl:for-each>
        </tr>
      </xsl:for-each>
    </tbody>
  </table>
</xsl:template>

It's probably actually not a good idea to use the value of the
<caption> elements to work out what each item contains; if you had a
'type' attribute or something that was less likely to change then that
would be better, but at the moment the caption is the only thing that
you can really use.

Cheers,

Jeni

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


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


Current Thread