• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to use the year-from-dateTime function

 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I am trying to use fn:year-from-dateTime to get year from a variable that consists of "29/07/09" as below

<xsl:value-of select="fn:year-from-dateTime(xs:date('29/07/09'))">

where 'fn' prefix refers to http://www.w3.org/2005/02/xpath-functions
and 'xs' prefix refers to http://www.w3.org/2001/XMLSchema

and I am getting below error while running transformation from java...

'The first argument to the non-static Java function 'date' is not a valid object reference.'
FATAL ERROR: 'Could not compile stylesheet'



Can some one help
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you using an implementation of XSLT which supports functions in this namespace? Or to put it another way, does xs:date work with other inputs but just not with this input, or does it never work?
 
Ram Korutla
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

It doesnt work with any input, any format.. I actually use a variable in place of "29/07/09" string and it doesnt work either


Thanks
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So what leads you to believe that your XSLT implementation supports functions in this namespace at all?

I'm not saying it doesn't; but since that namespace was designed long after XSLT was, it is quite possible that your transformer doesn't support it. I'm just asking what documentation you read which tells you that it does or doesn't.
 
Ram Korutla
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the inputs...

I am naive user of xslt and haven't read any document to confirm that the transformer supports this, I just referred the w3schools website for getting the year of a value and using it.

Frankly I am blank on whether it is supported or not. I have xmlapis.jar, xalan.jar and the xerces.jar in my classpath and just running the transformer on the xsls edited with the year-from-dateTime function.

Can you suggest anything on it
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's what I suspected. The w3schools tutorial is shamefully missing information about which functions work with XSLT 1.0 and which functions work with XSLT 2.0. Don't waste too much time using that as your primary reference, get yourself a proper book.
 
Ram Korutla
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I need to get to the basics first....

So, is there any thing that you can help me on this as a work around... I simply can't get away out of this...

If I cant make anything what you say I wouldnt trouble you again


Thanks
 
Ram Korutla
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I need to tell one more thing... I havent evaluated whether the year-from-dateTime function actually works...I havent got enough to that aspect yet.

In the statement

<xsl:value-of select="year-from-dateTime(xs:date('29/07/2009'))">, xs:date itself is failing not to talk of year-from-dateTime function..


Any help would be appreciated.

Thanks
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So you can't use either of those functions, then. How about just using string functions to extract the year part of the date?
 
Ram Korutla
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I just checked with the substring function and it actually works.

 
Ram Korutla
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
However, in my specific case, I wouldnt be knowing the kind of format of the date from which I need to extract the year and so on.

So irrespective of the format I need to extract the year, month, etc components and thus I believe I have to go with year-from-dateTime sort of options.


 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's possible to call Java code from an XSLT. But you won't find that covered in the web tutorials (along with a lot of other XSLT basics). Sorry, I'm afraid you're going to have to get a proper reference for that too.

Or alternatively you could use something which supports XSLT 2.0, as your Java code would have the same problem of not knowing the format of the date. (I'm not sure how you expect the xs:date function to deal with that problem but let's leave that aside for now.)
 
reply
    Bookmark Topic Watch Topic
  • New Topic