Project

Profile

Help

Support #5617

closed

fn:format-dateTime does not work as expected

Added by Juhi Gupta over 1 year ago. Updated over 1 year ago.

Status:
Closed
Priority:
Low
Assignee:
Category:
-
Sprint/Milestone:
-
Start date:
2022-07-27
Due date:
% Done:

0%

Estimated time:
Legacy ID:
Applies to branch:
Fix Committed on Branch:
Fixed in Maintenance Release:
Platforms:
Java

Description

Hello, I am trying to use fn:format-dateTime to parse the date from date time format to another, but I am getting weird errors

following is the sample xslt I am using

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns="http://www.w3.org/2005/xpath-functions"
  xmlns:func="http://ingka.ikea.com/"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:int="http://ikea.com/FUI/stockreport"
   xmlns:date="http://www.w3.org/2005/xpath-functions"
    version="3.0">

  <xsl:output method="text" indent="yes" omit-xml-declaration="yes" />
  <xsl:strip-space elements="*"/>    

    <xsl:param name="MessageReference" />    

	<xsl:template match="/">
		<xsl:variable name="transformed-xml">      
		<xsl:call-template name="body" />
		<xsl:copy-of select="/map"/>
		</xsl:variable>
		<!-- Added replace startment to print n/a as is, issue https://saxonica.plan.io/issues/5225-->
		<xsl:value-of select="xml-to-json($transformed-xml, map { 'indent' : true() })"/> 
	</xsl:template>

  
	<xsl:template name="body" >
		<map>
			<map key="MsgHeader">
				<xsl:call-template name="MsgHeader"/>
			</map> 
		</map>
	</xsl:template>    
  
  
	<xsl:template name="MsgHeader" >
		<string key="MsgNames"><xsl:value-of select="parse-dateTime('05/30/2018 09:00:00','MM/dd/yyyy HH:MMMX')"/></string> 
		<string key="MsgVersNo">1.0</string>
		<string key="MsgDateTime"><xsl:value-of select="format-dateTime(current-dateTime(),'[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01].[f001][Z00:00]')"/></string>
	</xsl:template>    
    
</xsl:stylesheet>

goal is to convert sample date time from 05/30/2018 09:00:00 to the standard format like "2018-05-30T09:00:00.000+02:00

So wanted to parse this date time, get into standard date time format and then finally using format-dateTime to get the required date time format.

but while using the above xslt, I keep getting error

Stylesheet compilation failed with 1 error(s): Error 1 at line 35:0 : Cannot find a 2-argument function named Q{http://www.w3.org/2005/xpath-functions}parse-dateTime(). External function calls have been disabled

tried on https://xsltfiddle.liberty-development.net/

Actions #3

Updated by Michael Kay over 1 year ago

  • Project changed from Non-Conformances to Saxon
Actions #4

Updated by Martin Honnen over 1 year ago

Saxon PE and EE support https://www.saxonica.com/html/documentation11/functions/saxon/parse-dateTime.html so you would need to use e.g. saxon:parse-dateTime (and PE or EE) instead of parse-dateTime in your code. As the error message says, there is no XPath 2 or 3 function named parse-dateTime.

Actions #5

Updated by Juhi Gupta over 1 year ago

Ah, do you mean doing something like this:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns="http://www.w3.org/2005/xpath-functions"
  xmlns:func="http://ingka.ikea.com/"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:int="http://ikea.com/FUI/stockreport"
   xmlns:date="http://www.w3.org/2005/xpath-functions"
   xmlns:saxon="http://saxon.sf.net/"
    version="3.0">

  <xsl:output method="text" indent="yes" omit-xml-declaration="yes" />
  <xsl:strip-space elements="*"/>    

    <xsl:param name="MessageReference" />    

	<xsl:template match="/">
		<xsl:variable name="transformed-xml">      
		<xsl:call-template name="body" />
		<xsl:copy-of select="/map"/>
		</xsl:variable>
		<!-- Added replace startment to print n/a as is, issue https://saxonica.plan.io/issues/5225-->
		<xsl:value-of select="xml-to-json($transformed-xml, map { 'indent' : true() })"/> 
	</xsl:template>

  
	<xsl:template name="body" >
		<map>
			<map key="MsgHeader">
				<xsl:call-template name="MsgHeader"/>
			</map> 
		</map>
	</xsl:template>    
  
  
	<xsl:template name="MsgHeader" >
		<string key="MsgNames"><xsl:value-of select="saxon:parse-dateTime('05/30/2018 09:00:00','MM/dd/yyyy HH:MMMX')"/></string> 
		<string key="MsgVersNo">1.0</string>
		<string key="MsgDateTime"><xsl:value-of select="format-dateTime(current-dateTime(),'[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01].[f001][Z00:00]')"/></string>
	</xsl:template>    
    
</xsl:stylesheet>

its throwing back similar error *Stylesheet compilation failed with 1 error(s): Error 1 at line 36:0 : Cannot find a 2-argument function named Q{http://saxon.sf.net/}parse-dateTime(). External function calls have been disabled *

but I think it could be because I am using Saxon HE

Do you think this function would be available in Saxon HE anytime?

Actions #6

Updated by Michael Kay over 1 year ago

It's our general policy that Saxon extensions to the W3C specifications require Saxon-PE or higher.

Actions #7

Updated by Juhi Gupta over 1 year ago

Okay! Thankyou :)

Actions #8

Updated by Michael Kay over 1 year ago

  • Status changed from New to Closed
  • Assignee set to Michael Kay

Please register to edit this issue

Also available in: Atom PDF