-1

I am trying to convert a string to date using castable function in XSLT. But i am getting a parsing error. I am using DataPower XI52 version 6.0.1.0. Does XI52 support this function?

Sample XML:

<Input><Date>2011-31-12</Date></Input>

My XSLT:

<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:fn="http://www.w3.org/2005/xpath-functions"
    xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xsl:template match="/">
    <xsl:variable name="Date" select="Input/Date"/>
    <xsl:value-of select="fn:cast($Date,'xs:string','xs:date', true())"/>
    </xsl:template>
</xsl:stylesheet>
michael.hor257k
  • 113,275
  • 6
  • 33
  • 51

3 Answers3

2

As far as I can tell from the release notes, DataPower only supports XSLT version 1.0. It supports XPath 2.0 functions but only as part of XQuery, not XSLT.

Ian Roberts
  • 120,891
  • 16
  • 170
  • 183
1

If (as it seems) you are trying to determine if the input contains a valid date - i.e. the equivalent of:

XSLT 2.0

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:template match="/">
    <xsl:variable name="Date" select="Input/Date"/>
    <xsl:value-of select="$Date castable as xs:date"/>
</xsl:template>

</xsl:stylesheet>

then try the following:

XSLT 1.0 (+ EXSLT)

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:date="http://exslt.org/dates-and-times"
extension-element-prefixes="date">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:template match="/">
    <xsl:variable name="Date" select="Input/Date"/>
    <xsl:value-of select="boolean(date:date($Date))"/>
</xsl:template>

</xsl:stylesheet>

This should work with any XSLT 1.0 processor that supports the EXSLT date:date() extension function, incl. IBM DataPower.

Note however, that it does NOT work with Saxon 6.5.5 that will happily output 2011-31-12 as the result of <xsl:value-of select="date:date('2011-31-12')"/> - despite the specification prescribing an empty string as the required result in this case.

michael.hor257k
  • 113,275
  • 6
  • 33
  • 51
0

Firstly, there is no function fn:cast() in any version of XSLT/XPath. Perhaps you are thinking of the "cast as" operator in XPath 2.0: Input/Date cast as xs:date.

Secondly, Datapower does not support XPath 2.0 in XSLT. XPath 2.0 is supported in XQuery only.

Refer Answer from Ian

Community
  • 1
  • 1
Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • HI Micheal, I have seen fn:cast in IBM datapower infocenter under XSLT and XPath extensions. Under the examples section of this function I could see the type supported in XPath 1.0.Not sure if my understanding is correct. Also could you please let me know how to handle above data type conversion in xslt – Omkar Venkata Sep 02 '14 at 05:19
  • 1
    Sorry, can't help you on anything DataPower-specific. And since it's about 10 years since I used XSLT 1.0, there are other people who can help you on that much better than I can. – Michael Kay Sep 02 '14 at 09:26