1
votes

Currently I'm struggeling to get to dates compared. More presizely I have a Person which has an attribute Death with the formatting YYYY-MM-DD and if the person is dead (Death < Currentdate) I want to write a latin-cross.

I tried the following approach:

<xsl:if test="@Death &lt;= current-date()">'symbol'</xsl:if>

But I only receive parsing errors form the browser. I'm using XSL version 1.0 with no namespaces except xmlns:xsl="http://www.w3.org/1999/XSL/Transform" of course.

Where is the error?

2
current-date() is available in XSLT 2.0, but not in XSLT 1.0.mzjn
"if the person is dead (Death < Currentdate)" You have people with dates of death in the future??! Who do you work for?michael.hor257k
But would this syntax work? @michael.hor257k the fact that non skilled users are able to submit xml forces me to check itCurunir
I don't understand what you're asking.michael.hor257k
I want to know how to determine if a date was before the current date.Curunir

2 Answers

1
votes

Ignoring the particular semantics of what it means for a date of death to be in the future, the general problem of comparing dates in YYYY-MM-DD format can be solved as follows:

  • In XSLT 2.0, use xs:date($x) < xs:date($y)

  • In XSLT 1.0, use number(translate($x, '-', '')) < number(translate($x, '-', ''). This is because in XSLT 1.0, the "<" operator only applies to numbers, and we can convert the date to a (meaningless but comparable) number by stripping the hyphens.

0
votes

I believe that:

<xsl:if test="@Death">

should be quite sufficient for testing. That is unless the living people have an empty Death attribute. In such case use:

<xsl:if test="string(@Death)">