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: Q on display order


Hi Walter,

> I so thought I would create a new XML node to define the data I wanted to
> display (a sub-set of the complete data) and in what order I would like thde
> columns to be in.

That sounds like a good way to do it.

You need to have two variables: one to hold the information about the
order of the columns, and another to hold the data itself.  So let's
say you've defined those:

<xsl:variable name="data" select="/data/item" />
<xsl:variable name="columns"
              select="document('tables.xml')/titles/display" />

(Of course you might have to adjust the above to get the data you
need, but I hope this gives an idea of what you're after.)

Now, when you create the table you first want to create a header row,
with one header per column.  So:

   <table>
      <thead>
         <tr>
            <xsl:for-each select="$columns">
               <th><xsl:value-of select="." /></th>
            </xsl:for-each>
         </tr>
      </thead>
      ...
   </table>

Now, for the body of the table, you need to have one row per data
item, and one cell in each row per column:

   <table>
      <thead>
         ...
      </thead>
      <tbody>
         <xsl:for-each select="$data">
            <xsl:variable name="datum" select="." />
            <xsl:for-each select="$columns">
               <xsl:variable name="column" select="." />
               <td>...</td>
            </xsl:for-each>
         </xsl:for-each>
      </tbody>
   </table>

When you're filling in each table cell, you need to get the relevant
bit of data for each data item.  I'm going to assume that the 'id'
attributes on the columns indicate the name of an attribute on each
data item, so the data looks like:

  <item num="..." date="..." curr_dest="..."
        media="..." reason="..." comment="..." />

If so, then given a column and a data item, you can get the relevant
data for the column by finding the value of the attribute on the data
item that matches the id on the column.  In other words:

  $datum/@*[name() = $column/@id]

So slotting that in you get:

   <table>
      <thead>
         ...
      </thead>
      <tbody>
         <xsl:for-each select="$data">
            <xsl:variable name="datum" select="." />
            <xsl:for-each select="$columns">
               <xsl:variable name="column" select="." />
               <td>
                  <xsl:value-of select="$datum/@*[name() = $column/@id]" />
               </td>
            </xsl:for-each>
         </xsl:for-each>
      </tbody>
   </table>

Now you might have a more complicated match between the column id and
the information you want from the datum.  In that case, you might need
to have an xsl:choose that tests the id of the column and gives you
the relevant information, something like:

  <xsl:choose>
     <xsl:when test="$column/@id = 'num'">
        <xsl:value-of select="@num" />
     </xsl:when>
     <xsl:when test="$column/@id = 'date'">
        <xsl:value-of select="concat(@day, '/', @month, '/', @year)" />
     </xsl:when>
     ...
  </xsl:choose>

I hope that helps get you started,

Jeni

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



 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]