current year
current year
hi,
how can i get the current year to display - i am declaring <xsl:param name="" /> but what should i enclose in the brackets to grab the current date or year?
how can i get the current year to display - i am declaring <xsl:param name="" /> but what should i enclose in the brackets to grab the current date or year?
Re: current year
Hi,
For XSLT 1.0 there is no date or time function. You will have to use an extension that provides that. A readily available extension in Oxygen is EXSLT, it can be used with both Saxon6.5.5 and Xalan transformers.
e.g. for ex:date()
For XSLT 2.0 you can simply use the function: current-date()
The stackoverflow community has a lot of topics and solutions for things like this:
http://stackoverflow.com/questions/1575 ... rrent-date
Regards,
Adrian
For XSLT 1.0 there is no date or time function. You will have to use an extension that provides that. A readily available extension in Oxygen is EXSLT, it can be used with both Saxon6.5.5 and Xalan transformers.
e.g. for ex:date()
Code: Select all
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ex="http://exslt.org/dates-and-times" extension-element-prefixes="ex">
<xsl:template match="/">
<xsl:value-of select="ex:date()"/>
</xsl:template>
</xsl:stylesheet>
The stackoverflow community has a lot of topics and solutions for things like this:
http://stackoverflow.com/questions/1575 ... rrent-date
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Re: current year
hi adrian,
thanks for reply, the ex:year doesnt seem to work when trying to extract the year from my dob element i.e. <dob>YYYY-MM-DD</dob>
i have in my xslt: <xsl:param name="dobyear" select="(ex:year('dob'))" />
and then: <xsl:value-of select="$dobyear"/>
this is outputting NaN?
thanks for reply, the ex:year doesnt seem to work when trying to extract the year from my dob element i.e. <dob>YYYY-MM-DD</dob>
i have in my xslt: <xsl:param name="dobyear" select="(ex:year('dob'))" />
and then: <xsl:value-of select="$dobyear"/>
this is outputting NaN?
Re: current year
Hi,
You don't want the string 'dob', but the value of the element dob, so you should remove the single quotes around dob:
ex:year(dob)
Regards,
Adrian
You don't want the string 'dob', but the value of the element dob, so you should remove the single quotes around dob:
ex:year(dob)
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Re: current year
single quotes removed as you suggested, but its still returning NaN?
<xsl:param name="dobyear" select="(ex:year(dob))" />
<xsl:value-of select="$dobyear"/>
<xsl:param name="dobyear" select="(ex:year(dob))" />
<xsl:value-of select="$dobyear"/>
Re: current year
You need to take into account the XML context from the template where you put that code.
e.g.
For the input XML file:and the stylesheet:
The result is: 2011
Regards,
Adrian
e.g.
For the input XML file:
Code: Select all
<dob>2011-08-09</dob>
Code: Select all
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ex="http://exslt.org/dates-and-times" extension-element-prefixes="ex">
<xsl:template match="/">
<xsl:value-of select="ex:year(dob)"/>
</xsl:template>
</xsl:stylesheet>
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Re: current year
Hiya,
i think ive noticed that when calling this exslt extension for getting the current year, its breaking the internet explorer browser (version 9) so just displays raw xml only....ive copied over all the date xsl files into the same folder as my stylesheet and did the <xsl:import href="date.xsl" />, but oxygen is throwing up a lot of compile errors? any advice?
i think ive noticed that when calling this exslt extension for getting the current year, its breaking the internet explorer browser (version 9) so just displays raw xml only....ive copied over all the date xsl files into the same folder as my stylesheet and did the <xsl:import href="date.xsl" />, but oxygen is throwing up a lot of compile errors? any advice?
Re: current year
Hi,
As you've guessed, Internet Explorer does not support EXSLT. You will have to use a different extension that is compatible with IE and the Microsoft ecosystem: msxsl
Searching the web, I've found this:
http://dpcarlisle.blogspot.com/2007/05/ ... ction.html
Regards,
Adrian
As you've guessed, Internet Explorer does not support EXSLT. You will have to use a different extension that is compatible with IE and the Microsoft ecosystem: msxsl
Searching the web, I've found this:
http://dpcarlisle.blogspot.com/2007/05/ ... ction.html
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com