Re: [xsl] Need help combing two elements

Subject: Re: [xsl] Need help combing two elements
From: "Fatbob" <fatbob73@xxxxxxxxxxx>
Date: Fri, 27 Mar 2009 09:00:54 -0400
Wow, thanks Vasu. I'll try it out ASAP.

----- Original Message ----- 
From: "vasu chakkera" <vasucv@xxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Thursday, March 26, 2009 6:29 PM
Subject: Re: [xsl] Need help combing two elements


> >Is it possible to combine two elements using XSL so that they display as
> one?
>
> Sure!!
>
> >>Here is a sample of my XML file...
>
> Here is your XSL
>
> Getting the month in numerals can be done in XSLT1 or XSLT2 .. I did
both..
> Use month1 for xslt1 and month2 for xslt2.
>
>
> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3
> org/1999/XSL/Transform" xmlns:myfunct = "myfunctions">
>  <xsl:template match="Row">
>   <!-- using xslt 2 -->
>   <xsl:variable name = "month2" select =
> myfunct:get-month-in-numerals(substring(Cell[1]/text(),1,3))"/>
>   <!-- using xslt 1-->
>   <xsl:variable name = "month1">
>    <xsl:call-template name="get-month-in-numerals">
>     <xsl:with-param name="month" select="substring(Cell[1]/text(),1,3)"/>
>    </xsl:call-template>
>   </xsl:variable>
>   <xsl:variable name = "date" select = "substring(Cell[1]/text(),5,2)"/>
>   <xsl:variable name = "year" select = "substring(Cell[1]/text(),9,4)"/>
>   <xsl:value-of select = "$year"/>
>   <xsl:text>-</xsl:text>
>   <xsl:value-of select = "$month2"/>
>   <xsl:text>-</xsl:text>
>   <xsl:value-of select = "$date"/>
>   <xsl:text>  </xsl:text>
>   <xsl:value-of select = "Cell[2]/text()"/>
>  </xsl:template>
>  <xsl:function name="myfunct:get-month-in-numerals">
>   <!-- xslt 2 solution -->
>   <xsl:param name="month"/>
>   <xsl:value-of select = "if($month = 'Jan') then '01' else if($month =
'Feb
> ) then '02' else if($month = 'Mar') then '03' else if($month = 'Apr') then
> 04' else if($month = 'May') then '05' else if($month = 'Jun') then '06'
else
> if($month = 'Jul') then '07' else if($month = 'Aug') then '08' else
> if($month = 'Sep') then '09' else if($month = 'Oct') then '10' else
> if($month = 'Nov') then '11' else if($month = 'Dec') then '12' else()"/>
>  </xsl:function>
>  <xsl:template name="get-month-in-numerals">
>   <!-- xslt 1 solution-->
>   <xsl:param name="month"/>
>   <xsl:choose>
>    <xsl:when test="$month ='Jan'">
>     <xsl:text>01</xsl:text>
>    </xsl:when>
>    <xsl:when test="$month ='Feb'">
>     <xsl:text>02</xsl:text>
>    </xsl:when>
>    <xsl:when test="$month ='Mar'">
>     <xsl:text>03</xsl:text>
>    </xsl:when>
>    <xsl:when test="$month ='Apr'">
>     <xsl:text>04</xsl:text>
>    </xsl:when>
>    <xsl:when test="$month ='May'">
>     <xsl:text>05</xsl:text>
>    </xsl:when>
>    <xsl:when test="$month ='Jun'">
>     <xsl:text>06</xsl:text>
>    </xsl:when>
>    <xsl:when test="$month ='Jul'">
>     <xsl:text>07</xsl:text>
>    </xsl:when>
>    <xsl:when test="$month ='Aug'">
>     <xsl:text>08</xsl:text>
>    </xsl:when>
>    <xsl:when test="$month ='Sep'">
>     <xsl:text>09</xsl:text>
>    </xsl:when>
>    <xsl:when test="$month ='Oct'">
>     <xsl:text>10</xsl:text>
>    </xsl:when>
>    <xsl:when test="$month ='Nov'">
>     <xsl:text>11</xsl:text>
>    </xsl:when>
>    <xsl:when test="$month ='Dec'">
>     <xsl:text>12</xsl:text>
>    </xsl:when>
>   </xsl:choose>
>  </xsl:template>
> </xsl:stylesheet>
>
> Hope this helps
>
> Vasu Chakkera
>
> -------Original Message------- 
>
> From: Fatbob
> Date: 26/03/2009 21:44:17
> To: XSL List
> Subject: [xsl] Need help combing two elements
>
> Hi everyone,
>
> Is it possible to combine two elements using XSL so that they display as
> One?
>
> Here is a sample of my XML file...
>
> <Row Type="Data">
> <Cell longDate="1143122100140" ChangeContext="FID=50020" ShowLink="true"
> Status="Normal">Mar 23, 2006</Cell>
> <Cell ChangeContext="FID=50020" ShowLink="true"
> Status="Normal">08:44</Cell>
> </Row>
>
> As you can see the first cell is a date and the second is a time, I need
to
> Combine and also convert that date to yyyy-MM-dd HH:mm format.
>
> So the example above would end up displaying like 2006-05-23 08:44. Well
the
>
> Time is fine, just the date needs to be converted.
>
> Is this possible to do in XSL?
>
> Thanks!

Current Thread