Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 1st, 2007, 04:50 AM
Friend of Wrox
 
Join Date: May 2005
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
 
Old February 1st, 2007, 05:45 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
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
 
Old February 1st, 2007, 06:24 AM
Friend of Wrox
 
Join Date: May 2005
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
 
Old February 1st, 2007, 07:03 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
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
 
Old February 1st, 2007, 07:45 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
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)
 
Old February 1st, 2007, 10:37 AM
Friend of Wrox
 
Join Date: May 2005
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





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





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