我试图编写一个XSLT函数来在某些日期之间进行选择。我将参数转换为xs:date
,然后用于获取其中两个参数之间的天数,并对其进行适当格式化。出于某种原因,termDate
变量被报告为未定义,即使我可以在Oxygen中的变量和节点/值集面板中看到参数引用和具有值的元素。
<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>
呼叫网站如下所示:
<ExpectedStatusEffectiveDate><xsl:value-of select="my:getStatusDate(RecentHireDate, TermDate, PreviousHireDate)"/></ExpectedStatusEffectiveDate>
示例XML源代码如下所示:
<?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>2000-01-13-08:00</TermDate> <!-- NOTE: this entry HAS a TermDate -->
</Entry>
</Data>
知道为什么termDate在两种情况下都不会被定义?
答案 0 :(得分:0)
我要把它归结为氧气虫。我不确定发生了什么变化,但在将函数隔离到自己的样式表后,它开始工作了。然后我把它复制回原版,一切似乎都有效。