RE: [xsl] Finding unique columns for building a table ...

Subject: RE: [xsl] Finding unique columns for building a table ...
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sat, 4 Jun 2005 19:54:43 +0100
The way you describe the problem:

"...storing that information, then
using that to reference values when iterating through rows?..."

suggests you are still thinking in terms of procedural programming, where
you tell the machine what order to do things in, and save data "early on"
for use "later".

The key to this kind of problem is to structure your code according to the
output you want to produce. Something like this:

<thead><tr>
<xsl:for-each select="timePoint[1]/Value/@Label">
  <td>Dose</td>
  <td><xsl:value-of select="."/></td>
</xsl:for-each>
</tr></thead>
<tbody>
<xsl:for-each select="timePoint">
  <tr>
    <td><xsl:value-of select="../@Dose"/></td>
    <xsl:for-each select="Value">
      <td><xsl:value-of select="."/></td>
    </xsl:for-each>
  </tr>
</xsl:for-each>
</tbody>

This is assuming the structure of your input is as regular as your sample
seems to suggest.

Michael Kay
http://www.saxonica.com/

 

> -----Original Message-----
> From: Richard Pugh [mailto:rpugh@xxxxxxxxxxxxxxxxxxx] 
> Sent: 03 June 2005 21:38
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] Finding unique columns for building a table ...
> 
> Hi all - I've just started using XSLT, so apologies if this is a basic
> question.  
> I would RTFM but my colleague has TFM so I can't at the moment!  
> 
> Anyway, the question:-
> 
> I have an XML document that looks like this ...
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <myRoot>
>  <myResults>
>   <myOutput Dose="1">
>    <timePoint time="1">
>     <Value name="P50" Label="Median">1924.836</Value>
>     <Value name="P2.5" Label="2.5%">1194.928</Value>
>     <Value name="P97.5" Label="97.5%">2598.446</Value>
>    </timePoint>
>    <timePoint time="2">
>     <Value name="P50" Label="Median">1851.636</Value>
>     <Value name="P2.5" Label="2.5%">1723.220</Value>
>     <Value name="P97.5" Label="97.5%">2024.470</Value>
>    </timePoint>
>    ...
> 
> What I want to do is build a table using 2/3 predefined 
> columns and all
> columns I have "value" for at each timePoint (eg. P2.5, P50 
> and P97.5 in
> this case).  So, I want my output to look like this:-
> 
> Dose	Time	Median	2.5%		97.5%
> 1	1	1924.836	1194.928	2598.446
> 1	2	1851.636	1723.220	2024.470
> .
> 
> I can see how I could iterate through and build the "rows" of 
> the table
> output, but I can't see how I figure out how many columns of 
> values there
> are in the first place.  Does anyone have a good approach to 
> finding all
> columns (P50, P2.5 and P97.5 in this case), storing that 
> information, then
> using that to reference values when iterating through rows?
> 
> Many thanks for any help .
> Rich.

Current Thread