Page 1 of 1

Variable undefined, when it looks like it shouldn't be

Posted: Tue Mar 01, 2016 9:34 pm
by jktravis
I'm trying to write an XSLT function to select between some dates. I have parameters that are being converted to `xs:date` and then used to get the number of days between two of them, and format them appropriately. For some reason, one of them is claiming it is undefined, even though I can see in the Variables and Nodes/Values Set panels that the parameter references and element that does have a value.

Code: Select all

<xsl:function name="my:getStatusDate">
<xsl:param name="rehire"/>
<xsl:param name="term"/>
<xsl:param name="hire"/>

<xsl:variable name="rehireDate" select="xs:date($rehire)" as="xs:date"/>
<xsl:variable name="termDate" select="xs:date($term)" as="xs:date"/>
<xsl:variable name="hireDate" select="xs:date($hire)" as="xs:date"/>
<xsl:variable name="dayDiffTermRehire" select="days-from-duration($termDate - $rehireDate)" as="xs:integer"/>

<xsl:choose>
<xsl:when test="$term != '' and not($term)">
<xsl:choose>
<xsl:when test="$dayDiffTermRehire > xs:integer(91)">
<xsl:value-of select="format-date($rehireDate, '[M01]/[D01]/[Y0001]')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="format-date($hireDate, '[M01]/[D01]/[Y0001]')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="format-date($hireDate, '[M01]/[D01]/[Y0001]')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:function>
The call site looks like this:

Code: Select all

<ExpectedStatusEffectiveDate><xsl:value-of select="my:getStatusDate(RecentHireDate, TermDate, PreviousHireDate)"/></ExpectedStatusEffectiveDate>
A sample XML source looks like this:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<Data>
<Entry>
<EmployeeFirstName>John</EmployeeFirstName>
<EmployeeLastName>Doe</EmployeeLastName>
<BirthDate>1940-01-01-01:00</BirthDate>
<RecentHireDate>1970-05-20-07:00</RecentHireDate>
<PreviousHireDate>1970-05-20-07:00</PreviousHireDate>
</Entry>
<Entry>
<EmployeeFirstName>Jane</EmployeeFirstName>
<EmployeeLastName>Doe</EmployeeLastName>
<BirthDate>1970-11-25-08:00</BirthDate>
<RecentHireDate>2003-12-22-08:00</RecentHireDate>
<PreviousHireDate>1970-06-19-07:00</PreviousHireDate>
<TermDate>1999-01-23-08:00</TermDate>
</Entry>
</Data>
Any idea why the termDate would be undefined in BOTH cases?

Re: Variable undefined, when it looks like it shouldn't be

Posted: Tue Mar 01, 2016 10:43 pm
by adrian
Hi,

At what point do you get the "variable undefined" message?
Do you see it when you run the transformation or when you try to evaluate the variable in XWatch?

Regards,
Adrian

Re: Variable undefined, when it looks like it shouldn't be

Posted: Wed Mar 02, 2016 12:30 pm
by adrian
Hi again,

I tested with your XML example and saw the "Variable undefined" message for termDate in the debugger (Variables view), but it is correct in this context since it depends on the TermDate element. In your first "Entry" element from the example there is no TermDate element. As soon as you get to the second Entry, the variable is evaluated.

Regards,
Adrian