Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT 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 February 1st, 2007, 04:50 AM
Friend of Wrox
 
Join Date: May 2005
Location: Nürnberg/München, , Germany.
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts
Default Date Type checking

Hallo all (or just Hallo Michael :D)

I have an XML data which has a DTD instead of Schema. I need to compare an element value if it is a date type formatted or not. Normally I could write some sort of code like
  <xsl:template match="shipDate">
    <xsl:if test="not(string(.) castable as xs:date)">
      <xsl:text>
Following shipDate value not a date: </xsl:text>
      <xsl:value-of select="."/>
    </xsl:if>
  </xsl:template>

but I am not sure if I can check my element value like that. It would be fine if someone can help me to solve this problem.



Your attitude determines your altitude
__________________
Your attitude determines your altitude
Reply With Quote
  #2 (permalink)  
Old February 1st, 2007, 05:45 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Provided you are using XSLT 2.0 your code looks fine. You don't need a schema to use the built-in types such as xs:date.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old February 1st, 2007, 06:24 AM
Friend of Wrox
 
Join Date: May 2005
Location: Nürnberg/München, , Germany.
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Michael

I have written this code chunk

<xsl:variable name="messageDate">
<xsl:value-of select="./messagedate"/>
</xsl:variable>
<xsl:if test ="not(string($messageDate) castable as xs:date)">
<xsl:element name="error">
    <xsl:attribute name="type">element</xsl:attribute>
    <xsl:attribute name="name">messagedate</xsl:attribute>
    <xsl:attribute name="message">Element is not in Date format</xsl:attribute>
</xsl:element>
</xsl:if>

but when I try to run this with an XML file I become this error

ERROR:
Expected token ')', found 'castable '.
not(string($messageDate) -->castable <-- as xs:date)

what can be the reason for it?

Actually I am using Visual Studio 2005 for this transformation and I don't know if it supports XSLT2.0 If not what should I do instead of castable? I know that XSLT 1.0 doesn't support the castable function.

Many thanks


Your attitude determines your altitude
Reply With Quote
  #4 (permalink)  
Old February 1st, 2007, 07:03 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

That message rather suggests that you are using an XSLT 1.0 processor rather than a 2.0 processor.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #5 (permalink)  
Old February 1st, 2007, 07:45 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Visual Studio certainly doesn't use XSLT 2.0 and will probably not do so until the version after next, unless they release some sort of add-in.

--

Joe (Microsoft MVP - XML)
Reply With Quote
  #6 (permalink)  
Old February 1st, 2007, 10:37 AM
Friend of Wrox
 
Join Date: May 2005
Location: Nürnberg/München, , Germany.
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you both for your replies. What I only could do is that I have written a looooong template (The format was CCYYMMDDHHMMSS CC for century like 19-20) which includes the variables (with substring) and in a choose operation I have tested their values. I HATE MICROSOFT.

Your attitude determines your altitude
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
Regular expression with date type ? nobitavn94 ASP.NET 1.0 and 1.1 Professional 2 December 21st, 2006 05:43 AM
date type queries mohiddin52 Access 5 July 29th, 2005 03:32 PM
date type queries mohiddin52 Access 1 January 11th, 2005 01:41 PM
date type queries mohiddin52 Access 1 March 19th, 2004 03:05 PM
Compile Time Data Type Checking c3nty@yahoo.com C# 0 September 18th, 2003 01:27 AM



All times are GMT -4. The time now is 04:15 PM.


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