cancel
Showing results for 
Search instead for 
Did you mean: 

PI / HCI sort node on date

former_member207428
Participant
0 Kudos

Hello everyone,

another (simple?) question : let's say we have following node structure :

/compoundemployee/person/employment_information

     custom_string1

     end_date

     start_date

     user_id

     ...

     job_information

          company

          location

          ...

We wish to sort the node employment information by start_date. Can this be achieved somehow via graphical mapping (sort / sortbykey) ? I only see as a rule for comparing values 'case insensitive', 'case sensitive', 'float number', but no date.

I'm working on a a Groovy script to achieve this, but if it's can somehow be done standard ?

Thanks !

Accepted Solutions (1)

Accepted Solutions (1)

former_member182412
Active Contributor
0 Kudos

Hi Kevin,

You can use below mapping to sort the date.

All other fields you can use below mapping, for example user_id field mapping.

Regards,

Praveen.

former_member186851
Active Contributor
0 Kudos

Praveen that's a good trick. Will it work for all cases?

former_member182412
Active Contributor
0 Kudos

Hi Raghu,

Yes it will work for all cases.

Regards,

Praveen.

former_member186851
Active Contributor
0 Kudos

Nice one praveen.

former_member207428
Participant
0 Kudos

Excellent, thanks !

Answers (1)

Answers (1)

former_member186851
Active Contributor
0 Kudos

Hello Kevin,

I believe this is not possible using SortbyKey function.

You need to have a UDF/Groovy script.

former_member207428
Participant
0 Kudos

Hi Raghuraman,

I solved this in HCI by using a mapping step -> New XSL Mapping.

The XSL file needs to be in the \src\main\resources\mapping folder.

Example using XSL 1.0 :

  • date format is yyyy-mm-dd
  • sorting of employment_information on start_date

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

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output encoding="cp1252" />

  <xsl:template match="queryCompoundEmployeeResponse/CompoundEmployee/person">

    <xsl:copy>

      <xsl:apply-templates select="employment_information">

      <!--  concat year, month, day -->

        <xsl:sort select="concat(

                  substring(start_date, 1, 4),

                  substring(start_date, 6, 2),

                  substring(start_date, 9, 2)

                  )"/>

      </xsl:apply-templates>

    </xsl:copy>

  </xsl:template>

  <xsl:template match="@* | node()">

    <xsl:copy>

      <xsl:apply-templates select="@* | node()"/>

    </xsl:copy>

  </xsl:template>

</xsl:stylesheet>