Re: [xsl] Transformation assistance please..

Subject: Re: [xsl] Transformation assistance please..
From: "Jay Bryant" <jay@xxxxxxxxxxxx>
Date: Mon, 31 Jul 2006 10:22:44 -0500
Hmmm, Bret became Eugene....

Whether you use a 12-hour clock or a 24-hour clock makes a big difference.
In XSLT 1.0, sorting by time is a pain, but it's a lot easier if you use a
24-hour clock. If you use a 24-hour clock, then you can multiply the value
before the colon by 60 and add it to the value after the colon. If you use a
12-hour clock, you have to determine A.M or P.M and take additional steps
(which I'm sure you can figure out).

So, assuming you use a 24-hour clock, change:

<xsl:template match="cardiacOutputTime1">
  <table>
    <tr>
      <th>Time</th>
      <th>Stage</th>
      <th>CO</th>
      <th>O2</th>
      <th>SpO2</th>
      <th>He</th>
      <th>xyz</th>
    </tr>
    <xsl:apply-templates/>
  </table>
</xsl:template>

to:

<xsl:template match="cardiacOutputTime1">
  <table>
    <tr>
      <th>Time</th>
      <th>Stage</th>
      <th>CO</th>
      <th>O2</th>
      <th>SpO2</th>
      <th>He</th>
      <th>xyz</th>
    </tr>
    <xsl:apply-templates>
      <xsl:sort select="number(normalize-space(substring-before(@time,
':'))) * 60 + number(normalize-space(substring-after(@time , ':')))"
data-type="number"/>
    </xsl:apply-templates>
  </table>
</xsl:template>

(By the way, one of your time values has an extraneous space. That's why I
added normalize-space().)

Unfortunately, time is scarce today, so how to dynamically generate the
heading values and match the data to the proper heading will have to wait. I
know I could do it, but I need to get on to my client's work. I bet someone
else on the list can help you with that part, though.

Jay Bryant
Bryant Communication Services



----- Original Message ----- 
From: <jeb501@xxxxxxxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Monday, July 31, 2006 1:14 AM
Subject: Re: [xsl] Transformation assistance please..


> Hi Jay,
>
> I tried with your XSL, the resulting HTML is not showing time sorted also,
>
> How to get the Heading of the table
>
>
>         <th>CO</th>
>         <th>O2</th>
>         <th>SpO2</th>
>         <th>He</th>
>         <th>xyz</th>
>
> based on type attribute, instead of typing it manualy in XSL.
>
> Regards
> Eugene
>
>
>
>
>
>
>              "Jay Bryant"
>              <jay@xxxxxxxxxxxx
>              >                                                          To
>                                        <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
>              31/07/2006 10:24                                           cc
>              AM
>                                                                    Subject
>                                        Re: [xsl] Transformation assistance
>              Please respond to         please..
>              xsl-list@xxxxxxxx
>               lberrytech.com
>
>
>
>
>
>
>
>
> Hi, Bret,
>
> Here's one solution.
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
>
>   <xsl:output method="html" indent="yes"/>
>
>   <xsl:template match="hemoDynamicTables">
>     <html>
>       <xsl:apply-templates/>
>     </html>
>   </xsl:template>
>
>   <xsl:template match="cardiacOutput">
>     <xsl:apply-templates/>
>   </xsl:template>
>
>   <xsl:template match="cardiacOutputTime1">
>     <table>
>       <tr>
>         <th>Time</th>
>         <th>Stage</th>
>         <th>CO</th>
>         <th>O2</th>
>         <th>SpO2</th>
>         <th>He</th>
>         <th>xyz</th>
>       </tr>
>       <xsl:apply-templates/>
>     </table>
>   </xsl:template>
>
>   <xsl:template match="measurement">
>     <tr>
>       <td><xsl:value-of select="@stage"/></td>
>       <td><xsl:value-of select="@time"/></td>
>       <xsl:choose>
>         <xsl:when test="@type='CO'">
>           <td><xsl:value-of select="."/> <xsl:value-of select="uom"/></td>
>           <td>&#160;</td>
>           <td>&#160;</td>
>           <td>&#160;</td>
>           <td>&#160;</td>
>         </xsl:when>
>         <xsl:when test="@type='O2'">
>           <td>&#160;</td>
>           <td><xsl:value-of select="."/> <xsl:value-of select="uom"/></td>
>           <td>&#160;</td>
>           <td>&#160;</td>
>           <td>&#160;</td>
>         </xsl:when>
>         <xsl:when test="@type='SpO2'">
>           <td>&#160;</td>
>           <td>&#160;</td>
>           <td><xsl:value-of select="."/> <xsl:value-of select="uom"/></td>
>           <td>&#160;</td>
>           <td>&#160;</td>
>         </xsl:when>
>         <xsl:when test="@type='He'">
>           <td>&#160;</td>
>           <td>&#160;</td>
>           <td>&#160;</td>
>           <td><xsl:value-of select="."/> <xsl:value-of select="uom"/></td>
>           <td>&#160;</td>
>         </xsl:when>
>         <xsl:when test="@type='xyz'">
>           <td>&#160;</td>
>           <td>&#160;</td>
>           <td>&#160;</td>
>           <td>&#160;</td>
>           <td><xsl:value-of select="."/> <xsl:value-of select="uom"/></td>
>         </xsl:when>
>         <xsl:otherwise>
>           <xsl:message>Error</xsl:message>
>         </xsl:otherwise>
>       </xsl:choose>
>     </tr>
>   </xsl:template>
>
> </xsl:stylesheet>
>
> I'm sure (because I can think of them) that there are other ways, but this
> one works and is (I hope) easy to follow. I tested it with Xalan-J.
>
> Welcome to XSLT.
>
> Jay Bryant
> Bryant Communication Services
>
> ----- Original Message -----
> From: "smithbm33" <smithbm33@xxxxxxxxx>
> To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
> Sent: Sunday, July 30, 2006 11:26 PM
> Subject: [xsl] Transformation assistance please..
>
>
> > Greetings,
> >
> > I am new to using XSLT 1.0 - I have the following XML
> > that I need to transform into HTML table format based
> > on attributes within the xml.  Any suggestions on how
> > to transform this would be of great assistance.
> >
> > Here is the XML:
> >
> > <hemoDynamicTables>
> >   <cardiacOutput>
> >     <cardiacOutputTime1>
> >       <measurement stage="Pre" time="12:01" type="CO"
> > uom="L/m">4.0</measurement>
> >       <measurement stage="Pre" time="12:02" type="O2"
> > uom="%">98</measurement>
> >       <measurement stage="Post" time="12:05" type="O2"
> > uom="%">88</measurement>
> >       <measurement stage="During" time="12:04"
> > type="SpO2" uom="%">40</measurement>
> >       <measurement stage="Pre" time="12:02 "
> > type="xyz" uom="ml">300</measurement>
> >       <measurement stage="During" time="12:02"
> > type="He" uom="%">100</measurement>
> >     </cardiacOutputTime1>
> >   </cardiacOutput>
> > </hemoDynamicTables>
> >
> > The HTML table output that I need is:
> >
> > Time  | Stage | CO  | O2 | SpO2 | He  | xyz |
> > ---------------------------------------------
> > 12:01 | Pre   | 4.0 |    |      |     |     |
> > ---------------------------------------------
> > 12:02 | Pre   |     | 98 |      |     | 300 |
> > ---------------------------------------------
> > 12:02 | During|     |    |      | 98  |     |
> > ---------------------------------------------
> > 12:04 | During|     |    | 40   |     |     |
> > ---------------------------------------------
> > 12:05 | Post  |     | 88 |      |     |     |
> > ---------------------------------------------
> >
> > Thanks - Bret
> >
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam?  Yahoo! Mail has the best spam protection around
> > http://mail.yahoo.com

Current Thread