Alnedru
Alnedru

Reputation: 2655

Filtering set of rows with XSLT

i have troubles filtering with XSLT, basically i have an xml, where i would like to get only those items where the Due Date falls into interval of 3 months ... i've written the following:

<xsl:variable name="TaskRows" select="/dsQueryResponse/Tasks/Rows/Row[@DueDate &gt; $IsoBeginQuartDate AND @DueDate &lt; $IsoEndQuartDate]"/>

But I get an error: "Failed seting processor stylesheet: expected token ']' found 'NAME' ...

IsoDates are calculated and formated dates in ISO format ...

Any idea, how to do it, or i can't use "AND" when filtering?

PS: i'm using XSLT 1.0

Upvotes: 0

Views: 670

Answers (2)

Tim C
Tim C

Reputation: 70598

There is case-sensitivity at work here! Try using 'and' instead of 'AND'.

Upvotes: 3

Mark Veenstra
Mark Veenstra

Reputation: 4739

Unfortunately in XSLT 1.0, you can't compare dates to see if a date is between two values.

What you could do is something like this:

<!-- Make sure to format this variables as YYYYMMDD -->
<xsl:variable name="$IsoBeginQuartDate">20130101</xsl:variable>
<xsl:variable name="$IsoBeginQuartDate">20131231</xsl:variable>

<!-- Make sure @DueDate also has the format YYYYMMDD, in this example I assume the DueDate has format YYYY-MM-DD -->
<xsl:variable name="TaskRows" select="/dsQueryResponse/Tasks/Rows/Row[translate(@DueDate, '-', '') &gt; $IsoBeginQuartDate and translate(@DueDate, '-', '') &lt; $IsoEndQuartDate]"/>

You now get errors, because &gt; and &lt; or not supported for strings or dates.

Upvotes: 1

Related Questions