tags:

views:

517

answers:

1

I have an XSLT function which checks whether the sent parameter is in YYYYMMDD format or not, in some conditions i am not getting any value to the function, during these conditions SAXON throwing below error

   **"An empty sequence is not allowed as the first argument of cda:isValidDate()"**

     any suggestions how to handle this situation ?

Thanks, Laxmikanth.S

+2  A: 

In XSLT there is no Null value. To represent a missing value, you can use a zero length string or an empty sequence. They are not the same thing - an empty sequence would return 0 from count($x) but a zero length string is a sequence containing one item of type xs:string which has a string length of 0 (count($x) = 1 and string-length($x) =0).

Most of the standard XPath functions accept either a zero length string or an empty sequence but your custom function may not.

The problem may be occuring if you're selecting the seqeunce of characters. For example, if you select the value of a nodes that contains the string the node does not exist, you'll get an empty sequence - but if the node exists and the value is empty, you'll get the empty-string.

Modify the way you select the value to always have the empty string (or wrap/change the isValidDate function to accept the empty-sequence). The following function defintion will accept the empty sequence and convert it to a zero length string

<xsl:function name="cda:isValidDate" as xs:boolean">
   <xsl:param name="datestring" as="xs:string?/>
   <xsl:varaible name="reallyastring" select="string($datestring)"/>
   Your code
</xsl:function>

The ? on the xs:string? param type allows one or no items to be provided. The string(...) function never returns an emptry string so will convert the empty sequence to a zero length string.

Robert Christie
Or use `xs:choose` to check whether the sequence is empty (`count() = 0`) before calling the function on it.
Pavel Minaev
how i can declare my function to accept the empty sequence ? is there any data type for that ?
Laxmikanth Samudrala
Have updated answer to show how to accept the empty sequence and convert it to the zero length string.
Robert Christie
after adding empty sequence for my function as above, now the parser(SAXON) throwing SequenceType Syntax error, saying Expected type name in SequenceType, found <function>, can i know how to handle this situation ?
lupefiasco