cancel
Showing results for 
Search instead for 
Did you mean: 

SAP CPI:Filter condition in XSLT with date compare

0 Kudos
1,452

Hi,

I am trying to filter the records in SAP CPI if the end_date is ge a date(I am adding the date which is set earlier.It would be in format yyyy-MM-DD) in XSLT.But my condition is failing with conversion errors.

This is what I am trying to use:

<?xml version="1.0" encoding="UTF-8" ?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xsl:output method="xml" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />

<xsl:param name="lastrun" select='2021-09-15'/>

<xsl:template match="/"> <Root>

<xsl:for-each select="/CompoundEmployee"> <xsl:if test="xs:date(person/employment_information[1]/end_date) ge xs:date('$lastrun')">

I am getting a error Invalid date "$lastrun" (Non-numeric year component).

I tried a lot of ways but not able to achieve this.

Any help is appreciated.

Accepted Solutions (0)

Answers (1)

Answers (1)

MortenWittrock
SAP Mentor
SAP Mentor
0 Kudos

Hi Shruthi

$lastrun should not be in single quotes. With the quotes, you are passing the literal string "$lastrun" to the xs:date function. So it's not getting the contents of the property lastrun, which is what you want. Remove the quotes, and you are good to go.

I've written a blog post about filtering XML elements, which you can check out for further inspiration.

Regards,

Morten