Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Converting a xml STRING displaying a long date, to dd/mm/yyyy

From: "Joe Fawcett" <joefawcett@---------.------>
To: NULL
Date: 12/17/2008 12:40:00 PM
All Microsoft stuff is version 1.0. Here's an example for you:

<?xml version="1.0" encoding="UTF-8" ?>

<xsl:stylesheet version="1.0"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

xmlns:my="http://example.com/dates">


<my:months>

<month index="01" name="January" />

<month index="02" name="February" />

<month index="03" name="March" />

<month index="04" name="April" />

<month index="05" name="May" />

<month index="06" name="June" />

<month index="07" name="July" />

<month index="08" name="August" />

<month index="09" name="September" />

<month index="10" name="October" />

<month index="11" name="November" />

<month index="12" name="December" />

</my:months>

<xsl:template match="/">

<dates>

<xsl:apply-templates select="Coupon/Event/Date" /></dates>

</xsl:template>

<xsl:template match="Date">

GMT: <xsl:value-of select="."/>

UK: <xsl:call-template name="gmtToUkDate">

<xsl:with-param name="gmtDate" select="." />

</xsl:call-template>

</xsl:template>

<!-- coverts date such as Friday 12 December 2008 to 14/12/2008-->

<xsl:template name="gmtToUkDate">

<xsl:param name="gmtDate"/>

<xsl:variable name="date" select="substring-before(substring-after($gmtDate, 
' '), ' ')" />

<xsl:variable name="monthName" 
select="substring-before(substring-after($gmtDate, concat($date, ' ')), ' 
')" />

<xsl:variable name="month" select="document('')/*/my:months/month[@name = 
$monthName]/@index" />

<xsl:variable name="year" select="substring-after($gmtDate, 
concat($monthName, ' '))" />

<xsl:value-of select="concat($date, '/', $month, '/', $year)"/>

</xsl:template>

</xsl:stylesheet>




-- 

Joe Fawcett (MVP - XML)

http://joe.fawcett.name


"Savvoulidis Iordanis" <SavvoulidisIordanis@d...> wrote 
in message news:1FBD81DF-3216-40F1-B18E-D746F5C8A477@m......
> Thanks for the response Joe.
>
> How do I figure out the XSLT version? I use .NET3.5 with VS2008.
>
> I read your recommendations, but I was hoping for a real XSLT example for 
> my
> case. As I mentioned , I'm a begginer in XML/XSLT and the things I've done
> with them, are far beyond my expectations for now. Also, time is running 
> out
> for my project (as always happens!) and a XSLT research/training is out of
> the question. Sure later, I'll start delving in more depth.
>
> I really liked the other option, about VB.NET. How could I call a VB.NET
> function that does the transformation and inject a "14/12/2008" string, in 
> my
> CSV result along with the other column data?
>
> Following, is an excerpt of my XML file.
>
> <?xml version="1.0" encoding="utf-8"?>
> <Coupon type="FOOTBALL">
>     <Event code="200">
>            <Status>ACTIVE</Status>
>            <League>GE2</League>
>            <Date>Monday 22 December 2008</Date>
>            <Time>19:00</Time>
>            <Code>200 </Code>
>            <Apodosi1>1,80</Apodosi1>
>            <HomeTeamAdvantage />
>            <HomeTeam>KOBLENTZ</HomeTeam>
>            <ApodosiX>3,15</ApodosiX>
>            <AwayTeam>INGOLDSTAD</AwayTeam>
>            <AwayTeamAdvantage />
>            <Apodosi2>3,50</Apodosi2>
>            <Apodosi1X>1,15</Apodosi1X>
>            <Apodosi12>1,19</Apodosi12>
>            <ApodosiX2>1,66</ApodosiX2>
>            <ApodosiHalf1>2,30</ApodosiHalf1>
>            <ApodosiHalfX>1,90</ApodosiHalfX>
>            <ApodosiHalf2>3,75</ApodosiHalf2>
>            <ApodosiUNDER>1,75</ApodosiUNDER>
>            <ApodosiOVER>1,70</ApodosiOVER>
>            <ApodosiSOG01>3,20</ApodosiSOG01>
>            <ApodosiSOG23>1,80</ApodosiSOG23>
>            <ApodosiSOG46>3,00</ApodosiSOG46>
>            <ApodosiSOG7>15,00</ApodosiSOG7>
>        </Event>
>        <Event code="201">
>            <Status>COMPLETE</Status>
>            <League>EN2</League>
>            <Date>Friday 12 December 2008</Date>
>            <Time>19:00</Time>
>            <Code>200 </Code>
>            <Apodosi1>1,85</Apodosi1>
>            <HomeTeamAdvantage />
>            <HomeTeam>WATFORD</HomeTeam>
>            <ApodosiX>3,15</ApodosiX>
>            <AwayTeam>COVENTRY</AwayTeam>
>            <AwayTeamAdvantage />
>            <Apodosi2>3,50</Apodosi2>
>            <Apodosi1X>1,15</Apodosi1X>
>            <Apodosi12>2,19</Apodosi12>
>            <ApodosiX2>1,66</ApodosiX2>
>            <ApodosiHalf1>2,30</ApodosiHalf1>
>            <ApodosiHalfX>3,90</ApodosiHalfX>
>            <ApodosiHalf2>3,75</ApodosiHalf2>
>            <ApodosiUNDER>1,65</ApodosiUNDER>
>            <ApodosiOVER>1,70</ApodosiOVER>
>            <ApodosiSOG01>3,20</ApodosiSOG01>
>            <ApodosiSOG23>2,80</ApodosiSOG23>
>            <ApodosiSOG46>4,00</ApodosiSOG46>
>            <ApodosiSOG7>18,00</ApodosiSOG7>
>        </Event>
>        <Event code="202">
>            <Status>ACTIVE</Status>
>            <League>EN1</League>
>            <Date>Saturday 27 December 2008</Date>
>            <Time>19:00</Time>
>            <Code>200 </Code>
>            <Apodosi1>1,85</Apodosi1>
>            <HomeTeamAdvantage />
>            <HomeTeam>ARSENAL</HomeTeam>
>            <ApodosiX>3,15</ApodosiX>
>            <AwayTeam>CARDIFF</AwayTeam>
>            <AwayTeamAdvantage />
>            <Apodosi2>3,50</Apodosi2>
>            <Apodosi1X>1,15</Apodosi1X>
>            <Apodosi12>2,19</Apodosi12>
>            <ApodosiX2>1,66</ApodosiX2>
>            <ApodosiHalf1>2,30</ApodosiHalf1>
>            <ApodosiHalfX>3,90</ApodosiHalfX>
>            <ApodosiHalf2>3,75</ApodosiHalf2>
>            <ApodosiUNDER>1,65</ApodosiUNDER>
>            <ApodosiOVER>1,70</ApodosiOVER>
>            <ApodosiSOG01>3,20</ApodosiSOG01>
>            <ApodosiSOG23>2,80</ApodosiSOG23>
>            <ApodosiSOG46>4,00</ApodosiSOG46>
>            <ApodosiSOG7>18,00</ApodosiSOG7>
>        </Event>
> </Coupon> 




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent