0

Trying to convert date to specific format but getting error:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.openapplications.org/oagis/9"
xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xsl:variable name="origDate" select="row[@num='6']/cell[@num='2']"/>
<PromisedDeliveryDateTime><xsl:value-of select="format-date(xs:date($origDate), '[Y] [M] [D]')" /></PromisedDeliveryDateTime>

But I get the error:

Failed to transform XQMessage part, index=0 (Invalid date "30.11.2011"
(Non-numeric component)

1 Answer 1

3

The xs:date() constructor function expects a string in ISO date format: 2011-11-30. To manipulate dates in other formats you first need to convert them to ISO format, which you can do for example as

string-join(reverse(tokenize($in, '.')), '-')
Sign up to request clarification or add additional context in comments.

2 Comments

thanks! But still something wrong: <xsl:variable name="origDate" select="row[@num='6']/cell[@num='2']"/> <xsl:variable name="origDate" select="string-join(reverse(tokenize($origDate, '.')), '-')"/> <PromisedDeliveryDateTime><xsl:value-of select="format-date(xs:date($origDate), '[Y] [M] [D]')" /></PromisedDeliveryDateTime> Failed to transform XQMessage part, index=0 (Invalid date "----------" (Year is less than four digits)
@VextoR No-one is going to read XML in the comment feed. Update your question and also mention what XSLT processor your are using.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.