cancel
Showing results for 
Search instead for 
Did you mean: 

XSLT Mapping

Former Member
0 Kudos

Hi Experts,

I have this question on XSLT Mapping.

My requirement is to check modified date (Personal information, Address Information) in each Person.

If modified date is less than last run date then exclude that parent node from Person.

E.g. Source XML below – Also attached with this Question.

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

<root>

  <Person>

  <PersonalInformation>                  
     <AinNo>718459</AinNo>

     <FirstName>A</FirstName>

     <LastName>Sharma</LastName>

     <ModifiedDate>07-06-2014 01:01:01</ModifiedDate>

  </PersonalInformation>

  <AddressInformation>                   
     <AddressLine1>Line1</AddressLine1>

     <AddressLine2>Line2</AddressLine2>

     <AddressLine3>Line3</AddressLine3>

     <City>New Delhi</City>

     <State>Delhi</State>

     <Country>India</Country>

     <PinCode>110001</PinCode>

     <ModifiedDate>04-06-2014 01:01:01</ModifiedDate>

</AddressInformation>

</Person>

<Person>

<PersonalInformation>

     <AinNo>718460</AinNo>

     <FirstName>B</FirstName>

     <LastName>Sharma</LastName>

     <ModifiedDate>04-06-2014 01:01:01</ModifiedDate>

</PersonalInformation>

<AddressInformation>

     <AddressLine1>BLine1</AddressLine1>

      <AddressLine2>BLine2</AddressLine2>

     <AddressLine3>BLine3</AddressLine3>

     <City>Noida</City>

     <State>UP</State>

     <Country>India</Country>

     <PinCode>120120</PinCode>

     <ModifiedDate>08-06-2014 01:01:01</ModifiedDate>

</AddressInformation>

</Person>

<LastRunDate>05-06-2014 11:59:59</LastRunDate>

</root>

E.g.

LastRunDate = 05-06-2014 11:59:59

i.e. Last time interface run on 05 June. Now requirement is to exclude all those parent nodes from person where last Modified date is less than last-run-date.

So Now My Question is on XSLT : What should be XSLT Message to exclude this extra data .

My Expected result message would be something like below.

From first Person Address information is removed as it was changed before last run date.

From Second Personal information removed because it was changed before last run date.

And hence result would be persons with only delta changes( changes from last run date).

 

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

<root>

<Person > ------ Person 1

<PersonalInformation>

     <AinNo>718459</AinNo>

     <FirstName>A</FirstName>

     <LastName>Sharma</LastName>

     <ModifiedDate>07-06-2014 01:01:01</ModifiedDate>

</PersonalInformation>

</Person>

<Person > ----- Person 2

<AddressInformation>

     <AddressLine1>BLine1</AddressLine1>

     <AddressLine2>BLine2</AddressLine2>

     <AddressLine3>BLine3</AddressLine3>

     <City>Noida</City>

     <State>UP</State>

     <Country>India</Country>

     <PinCode>120120</PinCode>

      <ModifiedDate>08-06-2014 01:01:01</ModifiedDate>

</AddressInformation>

</Person>

<LastRunDate>05-06-2014 11:59:59</LastRunDate>

</root>

Accepted Solutions (1)

Accepted Solutions (1)

iaki_vila
Active Contributor
0 Kudos

Hi Prabhat,

If your dates are with the format dd-MM-YYYY, you can change the order to can compare them. With this XSL I get your target:


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

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

    <xsl:template match="/">

        <xsl:variable name="lastRunDate">

            <xsl:value-of select="concat(substring(root/LastRunDate,7,4),substring(root/LastRunDate,4,2),substring(root/LastRunDate,1,2))"/>

        </xsl:variable>

        <root>

            <xsl:for-each select="/root/Person">

                <xsl:variable name="dateM">

                    <xsl:value-of select="concat(substring(./PersonalInformation/ModifiedDate,7,4),substring(./PersonalInformation/ModifiedDate,4,2),substring(./PersonalInformation/ModifiedDate,1,2))"/>

                </xsl:variable>

                <xsl:if test="$lastRunDate &lt; $dateM">

                    <xsl:copy-of select="."/>

                </xsl:if>

            </xsl:for-each>

        </root>

    </xsl:template>

</xsl:stylesheet>

I tried with this source XML:


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

<root>

    <Person>

        <PersonalInformation>

            <AinNo>718459</AinNo>

            <FirstName>A</FirstName>

            <LastName>Sharma</LastName>

            <ModifiedDate>10-06-2014 01:01:01</ModifiedDate>

        </PersonalInformation>

        <AddressInformation>

            <AddressLine1>Line1</AddressLine1>

            <AddressLine2>Line2</AddressLine2>

            <AddressLine3>Line3</AddressLine3>

            <City>New Delhi</City>

            <State>Delhi</State>

            <Country>India</Country>

            <PinCode>110001</PinCode>

            <ModifiedDate>10-06-2014 01:01:01</ModifiedDate>

        </AddressInformation>

    </Person>

    <Person>

        <PersonalInformation>

            <AinNo>718460</AinNo>

            <FirstName>B</FirstName>

            <LastName>Sharma</LastName>

            <ModifiedDate>04-06-2014 01:01:01</ModifiedDate>

        </PersonalInformation>

        <AddressInformation>

            <AddressLine1>BLine1</AddressLine1>

            <AddressLine2>BLine2</AddressLine2>

            <AddressLine3>BLine3</AddressLine3>

            <City>Noida</City>

            <State>UP</State>

            <Country>India</Country>

            <PinCode>120120</PinCode>

            <ModifiedDate>04-06-2014 01:01:01</ModifiedDate>

        </AddressInformation>

    </Person>

    <LastRunDate>09-06-2014 01:01:01</LastRunDate>

</root>

I get a target without the second person who his ModifedDate is before:


<?xml version="1.0" encoding="UTF-8"?><root><Person><PersonalInformation><AinNo>718459</AinNo><FirstName>A</FirstName><LastName>Sharma</LastName><ModifiedDate>10-06-2014 01:01:01</ModifiedDate></PersonalInformation><AddressInformation><AddressLine1>Line1</AddressLine1><AddressLine2>Line2</AddressLine2><AddressLine3>Line3</AddressLine3><City>New Delhi</City><State>Delhi</State><Country>India</Country><PinCode>110001</PinCode><ModifiedDate>10-06-2014 01:01:01</ModifiedDate></AddressInformation></Person></root>

Hope this helps.

Regards.

Former Member
0 Kudos

How would it work in case of my XML.


In my XML example cases :  Both Person has two parent Nodes ( Personal, Address ) and

In first Person - Parent personal information satisfy that condition.

In second Person - Parent Address information satisfy the condition.

So expected Result would be :-

Person -

     PersonalInformation -

          then its Fields.

Person -

     AddressInformation -

          then its Fields.

So will your code work that way ? How can i check with browser ?

iaki_vila
Active Contributor
0 Kudos

Hi Prabhat,

What tag date do you want to compare with LastRunDate in order to take or not to  take a person tag?

Regards.

Former Member
0 Kudos

compare last run date with Modified Date


This is basically to check only delta changes


assume interface run last time on last run date.


and now data is extracted . each parent has its own modified date . compare if modified date is after last run date then it is new/delta change else it was old change .

and old change we need not to sent . old changes were already sent during previous extraction.


got my point.

Former Member
0 Kudos

Also

I want to comapre modified date with LastRunDate in order to take or not to  take a personal and address tag.


Person Tag will always be there . but we need to further drill down and check which lower tag ( personal or address ) need to be remove.

Former Member
0 Kudos

Hello Prabhat,

In case of your scenario, it is better for the source to remove the older records before sending the data to PI as eventually it will cause performance issues in PI.

Rgds

Diptee

Answers (0)