Re: [xsl] Need help combing two elements

Subject: Re: [xsl] Need help combing two elements
From: "Fatbob" <fatbob73@xxxxxxxxxxx>
Date: Sun, 29 Mar 2009 20:11:14 -0400
Thanks for the reply Hermann, appreciate what everyone on this list is doing for me.

I'm still not able to get this to work, and it's frustrating me because it seems so simple. Perhaps it would help if I provided some of my XSL. The XML is I provided earlier with the except being...

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

and my XSL is the following (well a snippet of it, the part that actually creates the table, and where I'd like to join the two columns...

<xsl:template match="Table">
<fo:table text-align="left" width="100%" table-layout="fixed">
<xsl:if test="contains($reportType, 'Laborato')">
<fo:table-column column-number="1" column-width="20mm"/> <!-- Collect Date -->
<fo:table-column column-number="2" column-width="10mm"/> <!-- Collect Time -->
<fo:table-column column-number="3" column-width="30mm"/> <!-- Resulted Date/Time -->
<fo:table-column column-number="4" column-width="60mm"/> <!-- Test -->
<fo:table-column column-number="5" column-width="20mm"/> <!-- Result -->
<fo:table-column column-number="6" column-width="14mm"/> <!-- Units -->
<fo:table-column column-number="7" column-width="25mm"/> <!-- Normal Range -->
<fo:table-column column-number="8" column-width="13mm"/> <!-- Indicator -->
</xsl:if>


 <!-- Create number of columns needed -->
    <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>

 <!--Create Headers-->
 <fo:table-header>
  <fo:table-row>
   <xsl:for-each select="Row">
    <xsl:if test="@Type='Header'">
      <xsl:for-each select="Cell">
       <xsl:call-template name="LabHeaderCell"/>
      </xsl:for-each>
    </xsl:if>
   </xsl:for-each>
  </fo:table-row>
 </fo:table-header>

 <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>
</fo:table>
</xsl:template>


<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>


I believe I'm placing the example XSL that Hermann kindly provide in the wrong place in my XSL.

----- Original Message ----- From: "Hermann Stamm-Wilbrandt" <STAMMW@xxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Sunday, March 29, 2009 4:56 PM
Subject: Fw: [xsl] Need help combing two elements




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

So how would your sample XSLT work with my sample XML?

XSLT:


<xsl:template match="Row">
 <both a="{Cell[1]}" b="{Cell[2]}"/>,
</xsl:template>

Output:

<both a="Mar 23, 2006" b="08:44"/>


If you want to be able to transform an arbitrary number of <Cell> entries:>


Input:

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

XSLT:

<xsl:template match="Row">>
 <xsl:element name="row">>
   <xsl:for-each select="child::*"><xsl:value-of select="."/>;
</xsl:for-each>
 </xsl:element>
</xsl:template>>

OUTPUT:

<row>Mar 23, 2006; 08:44; </row>
<row>Mar 23, 2006; 08:44; text; </row>


Mit besten Gr|_en / Best wishes,


Hermann Stamm-Wilbrandt
Developer, XML Compiler
WebSphere DataPower SOA Appliances
----------------------------------------------------------------------
IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Martin Jetter
Geschdftsf|hrung: Erich Baier
Sitz der Gesellschaft: Bvblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294
----- Forwarded by Hermann Stamm-Wilbrandt/Germany/IBM on 03/29/2009 10:51
PM -----

            "Fatbob"
            <fatbob73@hotmail
            .con>                                                      To
                                      <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
            03/29/2009 11:06                                           cc
            PM
                                                                  Subject
                                      Re: [xsl] Need help combing two
            Please respond to         elements
            xsl-list@xxxxxxxx
             lberrytech.com








Thanks for the reply Wendell, but man I really slow at understanding XSL.


You sample looks to be quick simple, yet I'm not getting the desired
results. Perhaps it's because you're sample XML is quite a bit different
than my sample.

Here again is my sample (I simplified it further from my previous email)...

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

So how would your sample XSLT work with my sample XML?

Thanks!

----- Original Message -----
From: "Wendell Piez" <wapiez@xxxxxxxxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Friday, March 27, 2009 4:05 PM
Subject: Re: [xsl] Need help combing two elements


Fatbob:

Input:

<data>
  <one a="1"/>
  <two b="2"/>
</data>

XSLT:

<xsl:template match="data">
  <both a="{one/@a}" b="{two/@b}"/>
</xsl:template>

Output:
<both a="1" b="2"/>

Or more generally: decide on a context from which all the necessary data
components for your new element are visible (any context will do but some

are easier than others), and make the new element, pulling in whatever
data you want from wherever you find it.

In fact, it's pretty hard to write XSLT that doesn't do this, in a very
general way. If you think in terms of elements and attributes being nodes

on a tree, rather than stuff written with tags (as you really must to get

anywhere with XSLT), it starts seeming very normal.

Cheers,
Wendell

At 02:11 PM 3/27/2009, you wrote:
Thanks for taking the time to write that email. Greatly appreciate it.

To answer your question about moving to XSLT 2.0, unfortunately that is
not
an option. So I'll have to find a solution to merging the two cells and
formatting the date using whatever functionality is available in 1.0.

So far I'm still in the dark as to how I can merge the cells.





====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================

Current Thread