Hi all,
I have below xml input structure.
<?xml version="1.0" encoding="UTF-8"?>
<record>
<data>
<person>
<id>123</id>
<job_info>
<event>R</event>
<end_date>9999-12-31</end_date>
</job_info>
<job_info>
<event>5</event>
<end_date>9991-12-31</end_date>
</job_info>
<job_info>
<event>26</event>
<end_date>9999-07-31</end_date>
</job_info>
<job_info>
<event>H</event>
<end_date>9999-11-31</end_date>
</job_info>
</person>
</data>
<data>
<person>
<id>122</id>
<job_info>
<event>5</event>
<end_date>9999-12-31</end_date>
</job_info>
<job_info>
<event>H</event>
<end_date>9990-12-31</end_date>
</job_info>
</person>
</data>
</record>
******************************************************************************************
Requirement is to remove the job_info tag if end_date is not equals to '9999-12-31' and event not in(R,H,6). So the output will be
******************************************************************************************
<?xml version="1.0" encoding="UTF-8"?>
<record>
<data>
<person>
<id>123</id>
<job_info>
<event>R</event>
<end_date>9999-12-31</end_date>
</job_info>
</person>
</data>
<data>
<person>
<id>122</id>
</person>
</data>
</record>
**************************************************************************
Can you please tell me how can we achieve it by xslt mapping.
Any leads would be highly appreciated.
Thanks,
Divya
Request clarification before answering.
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<record>
<xsl:for-each select="/record/data">
<data>
<person>
<id>
<xsl:value-of select="person/id"/>
</id>
<xsl:for-each select="person/job_info">
<xsl:if test="(event != 'R' and event != 'H' and event != '6') and (end_date != '9999-12-31')">
<job_info>
<event>
<xsl:value-of select="event"/>
</event>
<end_date>
<xsl:value-of select="end_date"/>
</end_date>
</job_info>
</xsl:if>
</xsl:for-each>
</person>
</data>
</xsl:for-each>
</record>
</xsl:template>
</xsl:stylesheet>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Yatanveer,
Thank you so much for your response. This is a great help. Since I am new in XSLT mapping, so what if there are multiple (more than 15) tags in the XML node "PERSON".
I assume we will not be able to use all the 15 fields as
<id><xsl:value-ofselect="person/id"/></id>
Can you please assist me on how can I get all the 15 fields present under "person" and logic will be apply only on "JOB_INFO".
Your input would help me a lot.
Thanks,
Divya
| User | Count |
|---|---|
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.