Thursday, September 12, 2013

Simple XSLT to remove parent from parent child hier XML

There was a requirement to remove all the parents from the parent child hier and send only the child in XML.
Eg: 

 ListOfActionEmployee   
     Action_Emp
          Action 1
          Action 2
      /Action_Emp

     Action_Emp
          Action 3
          Action 4
    /Action_Emp
  .
  .
  .
/ListOfActionEmployee

Expected output

 ListOfExternalIO
          Action 1
          Action 2
          Action 3
          Action 4  
  .
  .
  .
/ListOfExternalIO

 Steps followed to remove the parents from the Hier
1. Created an outbound IO, for sending only the child i'e 'External IO'
2. Wrote XSLT as below
   ****************************************
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
 <xsl:output method="xml" indent="yes" encoding="utf-16"/>
<xsl:template match="/SiebelMessage">
<SiebelMessage MessageId="{@MessageId}" MessageType="{@MessageType}" IntObjectName="External IO" IntObjectFormat="{@IntObjectFormat}">
     <ListOfExternalIO>
        <ListOfAction>
                <xsl:apply-templates select="ListOfActionEmployee/ActionEmployee/ListOfAction"/>
        </ListOfAction>
    </ListOfExternalIO>
</SiebelMessage>
 </xsl:template>
<xsl:template match="ListOfActionEmployee/ActionEmployee/ListOfAction/Action">
    <Action>
        <Id><xsl:value-of select="ActivityUID"/></Id>
        <IntName>ActionId</IntName>
    </Action>   
</xsl:template>
</xsl:stylesheet>
*******************************************

 Please comment if you need any further detail.

No comments:

Post a Comment