tags:

views:

91

answers:

1

I have a scenario to validate date from incoming xml file, which has effectiveTime as a element, the format of that element can be one of them as below

1)

<effectiveTime value="YYYYMMDD"/>

or

2)

<effectiveTime>
    <low value="YYYYMMDD"/>
    <high value="YYYYMMDD"/>
</effectiveTime>

if the incoming file has the format specified as point 1 (as mentioned above), then i need to validate @value is in YYYYMMDD or not, if it is in other format (2nd), i need to verify low @value date is less than or equal to high @value or not.

I have this element (<effectiveTime>) in couple of the places in my incoming XML file, I would like to write one xsl:function which can validate this scenario and i would like to send node (here effectiveTime) as param to the xsl:function.

<xsl:function name="util:validateEffectiveTime" as="xs:boolean">
    <!-- I would like to know xml schema data type for the param -->
    <xsl:param name="effectiveTimeP" as="****"/>
</xsl:function>

Can i go ahead and create any xsl:function (util:validateEffectiveTime) with accepting node as a parameter to that xsl:function and also let me know the xml schema data type i need to assign to param (effectiveTimeP) ?

Thanks !

A: 

If you are passing the <effectiveTime> elements themselves to the function, then the function will always be receiving an Element in the effectiveTimeP parameter. Though if in doubt, the parameter types are optional so you can leave them off entirely.

For date validation, I would probably put that in its own function (since it will be necessary in three different places, since there are three locations that dates might appear). But in the second case, since the dates are in most-significant-part-first order (year, month, day), you can ensure that one is before the other by a simple numerical comparison.

Adam Batkin