current year
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
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
-
- Posts: 7
- Joined: Tue May 22, 2012 5:07 pm
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?
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
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
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
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
-
- Posts: 7
- Joined: Tue May 22, 2012 5:07 pm
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?
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
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
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service