Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XML
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 21st, 2005, 10:49 AM
Authorized User
 
Join Date: May 2005
Location: Waterlooville, HANTS, United Kingdom.
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default formatting strings / dates

Joe I need your help m8, google is not being very cooperative at all!

I have this xml:

<date>
   <dateTime value="6/June/2005 16:6:33" />
</date>


Using an .xslt stylesheet how on earth can I format that string so it
gets transformed to 6 Jun 2005?

I've tried:

<xsl:template match="QuoteTime/@value">
   <xsl:value-of select="format-date-time(., '%Y-%m-%dT%H:%M:%S%z')" />
</xsl:template>

And:

<xsl:template match="//instruction/Qtn_Tbl/QuoteTime">
   <xsl:value-of select="dt:format-date(@value, 'dd MMM yyyy')" />
</xsl:template>

etc etc - its not working!

I've tried various function calls like date() date-format() etc but it appears to me that they all work on .xsl and not .xslt!

I've been on Microsoft to have a look at their examples but they all don't appear to be working due to a namespace descrepancy!

xmlns:dt="http://xsltsl.org/date-time"

I have to admit to be simply creating these files in notepad and testing the stylesheet by opening them in IE rather using the Transform object in .Net...is this half of my problem or do I need to use .Net to transform the xml?

Why is .xsl so different to .xslt anyway! It's amazing, you go to the code downloads and flick through to Professional XSLT 2.0 downloads here and you will notice that every single stylesheet file is a .xsl and not a .xslt!

Am I missing something here?

Reply With Quote
  #2 (permalink)  
Old June 21st, 2005, 10:59 AM
mhkay's Avatar
Wrox Author
Points: 18,481, Level: 59
Points: 18,481, Level: 59 Points: 18,481, Level: 59 Points: 18,481, Level: 59
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You're confused about language dialects.

XSLT 1.0 was defined by W3C in 1999. During its development it was often referred to as XSL, and this name survives in the conventional prefix xsl:stylesheet and the conventional file extension style.xsl.

Before XSLT 1.0 came out, Microsoft produced a product based on a working draft of the spec, with many of their own extensions. Older Microsoft documents refer to this obsolete dialect as XSL, but most people call it WD-xsl, after the namespace used to identify it. THis dialect is essentially dead.

XSLT 2.0 is still in draft, and not supported by any Microsoft products. It includes functions such as format-dateTime().

XSLT 1.0 allows the function library to be extended in a vendor-specific namespace. The MSXML4 product includes some such extensions, specifically for date and time formatting.

There are also some extension functions for date and time handling in the EXSLT library, see www.exslt.org.

Hope this clarifies!

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old June 22nd, 2005, 04:46 AM
Authorized User
 
Join Date: May 2005
Location: Waterlooville, HANTS, United Kingdom.
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

To be honest...it's all a little bit confusing to me...xsl seems like such a big thing with so much promise that I want to dig deep and get as much out of this as possible but I seem to travel from one site to another trying to find answers but half the time I end up with error messages like not a valid XSLT pr XPath function!

There just seems to be so much ... I don't know..its all very cloudy to me at the moment but I guess its new to me that's all!

Reply With Quote
  #4 (permalink)  
Old June 22nd, 2005, 09:52 AM
Authorized User
 
Join Date: May 2005
Location: Waterlooville, HANTS, United Kingdom.
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Okay so after another load of searching I came across a page with a list of functions that did seem to work in xslt!

Below is the result of my work - If by any chance you know of a better way then please let me know. By the way I found that if I started a new value on another line it entered a space in hence the reason why it isn't so easy to read due to some of the closing tags being quickly followed by an opening tag!

Personally, I'm pretty happy with my effort...but it did take me some time!

the value being taken from the node is: - 6/June/2005 16:6:33
The value I want to show at the end is: - 6 June 2005 16:06


<xsl:template match="//someTime">
   <xsl:param name="dayDate" select="substring-before(@value, '/')" />
   <xsl:param name="afterDay" select="substring-after(@value, '/')" />
   <xsl:param name="monthDate" select="substring-before($afterDay, '/')" />
   <xsl:param name="afterMonth" select="substring-after($afterDay, '/')" />
   <xsl:param name="yearDate" select="substring-before($afterMonth, ' ')" />
   <xsl:param name="timeDate" select="substring-after($afterMonth, ' ')" />
   <xsl:param name="hourDate" select="substring-before($timeDate, ':')" />
   <xsl:param name="afterHour" select="substring-after($timeDate, ':')" />
   <xsl:param name="minuteDate" select="substring-before($afterHour, ':')" />


   <xsl:if test="string-length($dayDate) = 2" >
    <xsl:value-of select="$dayDate" />
   </xsl:if>
   <xsl:if test="string-length($dayDate) = 1" >
    0<xsl:value-of select="$dayDate" />
   </xsl:if>

   #160;<xsl:choose>
    <xsl:when test="string-length($monthDate) > 4" >
          <xsl:value-of select="substring($monthDate, 1, 3)" />
      </xsl:when>
      <xsl:otherwise>
      <xsl:value-of select="$monthDate" />
      </xsl:otherwise>
   </xsl:choose>
   #160;<xsl:value-of select="$yearDate" />

  at#160;<xsl:choose>
    <xsl:when test="string-length($hourDate) = 2" >
          <xsl:value-of select="$hourDate" />
      </xsl:when>
      <xsl:otherwise>
      0<xsl:value-of select="$hourDate" />
      </xsl:otherwise>
   </xsl:choose>:<xsl:if test="string-length($minuteDate) = 2" >
    <xsl:value-of select="$minuteDate" />
   </xsl:if><xsl:if test="string-length($minuteDate) = 1" >0<xsl:value-of select="$minuteDate" /></xsl:if>

</xsl:template>

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Formatting Dates dhoward SQL Language 4 January 30th, 2007 04:00 PM
Formatting For Between Dates hcweb Classic ASP Basics 7 February 8th, 2005 02:29 AM
formatting dates treasacrowe Classic ASP Basics 3 October 20th, 2004 06:52 PM
Formatting dates in XSL francislang XSLT 4 September 3rd, 2004 08:17 AM
Formatting Dates Louisa VB.NET 2002/2003 Basics 3 March 16th, 2004 05:52 AM



All times are GMT -4. The time now is 07:44 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.