This is in accordance with the specification at
 
http://www.saxonica.com/documentation/extensibility/function-result.html
 
It would be nice to support this mapping, but it's not currently designed into the product (and there's nothing in the JAXP interface that says it should be).
 
There are a number of technical issues here that make it more difficult than one might imagine to take a java.util.Date as input. Your example, new GregorianCalendar(1066, 9, 14), despite appearances, actually represents the date 14 Oct 1066 in the Julian calendar, which corresponds to the date 1066-10-20 in the proleptic Gregoarian calendar used in the xs:dateTime data type. So the conversion isn't trivial, especially as the date for switching from one calendar to the other depends on which country you are in. It would be possible to convert by calling setGregorianChange() on the supplied GregorianCalendar object, but that doesn't work easily because I can't really modify an object supplied by the caller.
 
The XQJ interface for XQuery also struggles with this: it maps an xs:dateTime not to a java.util.GregorianCalendar or java.util.Date object, but to an instance of javax.xml.datatype.XMLGregorianCalendar.
 
Michael Kay
http://www.saxonica.com/


From: saxon-help-bounces@lists.sourceforge.net [mailto:saxon-help-bounces@lists.sourceforge.net] On Behalf Of alan.painter@sgcib.com
Sent: 30 August 2006 16:56
To: saxon-help@lists.sourceforge.net
Cc: PAR-ITEC-DFI-FSI-Support@sgcib.com
Subject: [saxon] can't pass Date parameters that validate as xs:dateTime


Scratching big patchy spot at top of head but unable to figure out this one.

Trying to pass a java.util.Date parameter into a SaxonSA stylesheet and have it validate as an "xs:date" or "xs:dateTime" or any equivalent.

Always getting an error.


Minimal example XSLT: (SaxonParamTest.xslt)

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xs="http://www.w3.org/2001/XMLSchema"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  
                version="2.0">

        <xsl:output name="xml" method="xml" omit-xml-declaration="yes" indent="no" />
       
        <xsl:param    name="dateParam"   as="xs:dateTime"  />

        <xsl:template match="/">
                <xsl:message select="'dateParam = '"><xsl:value-of select="$dateParam"/></xsl:message>
        </xsl:template>

</xsl:stylesheet>

Called from a minimal example Java (SaxonParamTest.java):

public class SaxonParamTest {
       
    public static final String NULL_XML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
                                          + "<rootElement/>";

    public final static String jaxpXformFactProp = "javax.xml.transform.TransformerFactory";
    public final static String saxnXformFactImpl = "com.saxonica.SchemaAwareTransformerFactory";

    public static void main(String[] args) throws TransformerException {
               
        System.setProperty(jaxpXformFactProp, saxnXformFactImpl);
        TransformerFactory tfactory = TransformerFactory.newInstance();

        // Create a transformer for the stylesheet.
        Transformer transformer = tfactory.newTransformer(new StreamSource("./src/simpletest/SaxonParamTest.xslt"));
       
        // Add a date parameter
        Date keyDate = new GregorianCalendar(1066, 9, 14).getTime();
        System.out.println(keyDate.toString());
        transformer.setParameter("dateParam", keyDate);

        // Transform the source XML to System.out.
        transformer.transform(new StreamSource(new ByteArrayInputStream(NULL_XML.getBytes())),
                              new StreamResult(System.out));                
    }

}


Getting this error message:

Validation error
  FORG0001: Invalid dateTime value. Non-numeric component

Thanks for any pointers.

-alan
*************************************************************************
This message and any attachments (the "message") are confidential and intended solely for the addressee(s).
Any unauthorised use or dissemination is prohibited. E-mails are susceptible to alteration.   
Neither SOCIETE GENERALE nor any of its subsidiaries or affiliates shall be liable for the message if altered, changed or
falsified.
                              ************
Ce message et toutes les pieces jointes (ci-apres le "message") sont confidentiels et etablis a l'intention exclusive de ses
destinataires. Toute utilisation ou diffusion non autorisee est interdite. Tout message electronique est susceptible d'alteration. 
La SOCIETE GENERALE et ses filiales declinent toute responsabilite au titre de ce message s'il a ete altere, deforme ou falsifie.
*************************************************************************