xsl-list
[Top] [All Lists]

Re: [xsl] Need help combing two elements

2009-03-30 00:04:55
Hi Syd,

Well basically, this XSL is used to build a report. Here is a sample of the report that this XSL builds as it is now...

http://img12.imageshack.us/img12/7903/samplereport.jpg

What I'm trying to do is combine the first two columns into one column. So instead of having a column for date (the collect column), and a column for time (right next to Collect), I want that to be displayed in one column, similar to Resulted. Ultimately, I'd like to also convert the date to a different format (yyyy-MM-dd hh:mm), but one step at a time.

Well I didn't include LabHeaderCell, as that is not the part of the XSL that is giving my a head ache. LabHeaderCell is used to display the header (where you see Name:, MRN: Age: and Sex:). As for the variable $reportType, it's simply used to determine that this is a Laboratory report.

The part of the XSL that fills (not sure if that is the correct terminology) the table is...

 <fo:table-body>
     <xsl:for-each select="Row">
      <xsl:if test="@Type='Data'">
       <fo:table-row keep-together.within-column="always">
     <!--both a="$tempDate" b="$tempTime"/-->

<xsl:for-each select="Cell[position() = 1 or position() = 2 or position() = 3 or position() = 6 or position() = 7 or position() = 8 or position() = 9 or position() = 10]">
         <xsl:call-template name="LabDataCell"/>
        </xsl:for-each>
       </fo:table-row>
      </xsl:if>
     </xsl:for-each>
    </fo:table-body>

and...

<xsl:template name="LabDataCell">
 <xsl:choose>
  <xsl:when test="@Status='Panic'">
<fo:table-cell color="red" background-color="white" border="1pt solid black" wrap-option="wrap" overflow="hidden"> <fo:block font-size="8pt" padding="1mm" margin-left=".25mm" overflow="hidden" language="ru" hyphenate="true">
       <xsl:value-of select="."/>
      </fo:block>
     </fo:table-cell>
    </xsl:when>
    <xsl:otherwise>
<fo:table-cell color="black" background-color="white" border="1pt solid black" wrap-option="wrap" overflow="hidden"> <fo:block font-size="8pt" padding="1mm" margin-left=".25mm" overflow="hidden" language="ru" hyphenate="true">
       <xsl:value-of select="."/>
      </fo:block>
     </fo:table-cell>
    </xsl:otherwise>
   </xsl:choose>
</xsl:template>

So I figure Hermann's suggestion should go somewhere in the above snippet of XSL?

----- Original Message ----- From: "Syd Bauman" <Syd_Bauman(_at_)Brown(_dot_)edu>
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Sent: Sunday, March 29, 2009 11:05 PM
Subject: Re: [xsl] Need help combing two elements


and my XSL is the following (well a snippet of it, ...

Actually, it would probably be easier to provide advice if you sent
the entire XSLT (or a pointer to it), as it is quite difficult to
test what you sent, as we don't have access to $reportType,
LabHeaderCell, etc.

I've got your input:

<Row Type="Data">
 <Cell>Mar 23, 2006</Cell>
 <Cell>08:44</Cell>
</Row>

But what do you want the output to look like?


While we're here, though, some thoughts follow.

      <xsl:for-each select="Row">
       <xsl:if test="@Type='Header'">
         <xsl:for-each select="Cell">
           <fo:table-column/>
         </xsl:for-each>
       </xsl:if>
     </xsl:for-each>

Couldn't this be expressed a bit more simply as

     <xsl:for-each select="Row[(_at_)Type='Header']/Cell">
       <fo:table-column/>
     </xsl:for-each>

?

    <xsl:choose>
     <xsl:when test="@Status='Panic'">
<fo:table-cell color="red" background-color="white" border="1pt solid
         black" wrap-option="wrap" overflow="hidden">
         <fo:block font-size="8pt" padding="1mm" margin-left=".25mm"
           overflow="hidden" language="ru" hyphenate="true">
           <xsl:value-of select="."/>
         </fo:block>
       </fo:table-cell>
     </xsl:when>
     <xsl:otherwise>
<fo:table-cell color="black" background-color="white" border="1pt solid
         black" wrap-option="wrap" overflow="hidden">
         <fo:block font-size="8pt" padding="1mm" margin-left=".25mm"
           overflow="hidden" language="ru" hyphenate="true">
           <xsl:value-of select="."/>
         </fo:block>
       </fo:table-cell>
     </xsl:otherwise>
   </xsl:choose>

Since most of the content of the <when> and the <otherwise> are the
same, I'd be inclined to factor out the similarities:

 <xsl:template name="LabDataCell">
   <xsl:variable name="color">
     <xsl:choose>
       <xsl:when test="@Status='Panic'">red</xsl:when>
       <xsl:otherwise>black</xsl:otherwise>
     </xsl:choose>
   </xsl:variable>
   <fo:table-cell color="{$color}" background-color="white"
     border="1pt solid black" wrap-option="wrap" overflow="hidden">
     <fo:block font-size="8pt" padding="1mm" margin-left=".25mm"
       overflow="hidden" language="ru" hyphenate="true">
       <xsl:value-of select="."/>
     </fo:block>
   </fo:table-cell>
 </xsl:template>


I'm sure others on the list will point out if & where I'm wrong.


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--