Given a list of elements with a date attribute, for example,
<foo>
<bar date="2001-04-15"/>
<bar date="2002-01-01"/>
<bar date="2005-07-04"/>
<bar date="2010-11-10"/>
</foo>
I would like to retrieve the element closest to but not after a given date using XSLT.
Calling this function with parameter “2008-01-01” should print <bar date="2005-07-04">. Assume the context node is already <foo>.
I’m not sure what would be easier, but I could also set up three attributes: day, month, year, instead of having one date attribute.
Here’s an XSLT 2.0 option…
XML Input
XSLT 2.0
XML Output
Explanation of “foo” template…