Variable undefined, when it looks like it shouldn't be
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 1
- Joined: Tue Mar 01, 2016 9:21 pm
Variable undefined, when it looks like it shouldn't be
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.
The call site looks like this:
A sample XML source looks like this:
Any idea why the termDate would be undefined in BOTH cases?
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>
Code: Select all
<ExpectedStatusEffectiveDate><xsl:value-of select="my:getStatusDate(RecentHireDate, TermDate, PreviousHireDate)"/></ExpectedStatusEffectiveDate>
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>
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: Variable undefined, when it looks like it shouldn't be
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
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
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: Variable undefined, when it looks like it shouldn't be
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
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
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service