Hi there,
I have following XML and i want to transform it to my desire XML using XSLT ,i have succeded somewhat but not whole problem is solved .So I need help
Given is My Input XML
<?xml version = '1.0'?>
<ROWSET>
<irp_account num="1">
<IRP_CARRIER_ID_NUMBER>274845</IRP_CARRIER_ID_NUMBER>
<IRP_ACCOUNT_NUMBER>55002</IRP_ACCOUNT_NUMBER>
</irp_account>
<irp_account num="97">
<IRP_CARRIER_ID_NUMBER>957858</IRP_CARRIER_ID_NUMBER>
<IRP_ACCOUNT_NUMBER>59940</IRP_ACCOUNT_NUMBER>
<NAME_TYPE>LG</NAME_TYPE>
<NAME>SONNY DAVIS INC</NAME>
<ADDRESS_TYPE>MA</ADDRESS_TYPE>
</irp_account>
<irp_account num="98">
<IRP_CARRIER_ID_NUMBER>957858</IRP_CARRIER_ID_NUMBER>
<IRP_ACCOUNT_NUMBER>59940</IRP_ACCOUNT_NUMBER>
<NAME_TYPE>LG</NAME_TYPE>
<NAME>SONNY DAVIS INC</NAME>
<ADDRESS_TYPE>PH</ADDRESS_TYPE>
</irp_account>
</ROWSET>
With the use of XSLT i want to generate Output XML like this.
<?xml version="1.0"?>
<T0020>
<IRP_ACCOUNT>
<IRP_CARRIER_ID_NUMBER>274845</IRP_CARRIER_ID_NUMBER>
<IRP_ACCOUNT_NUMBER>55002</IRP_ACCOUNT_NUMBER>
<IRP_NAME>
<NAME_TYPE>LG</NAME_TYPE>
<NAME>A P SUPPLY CO</NAME>
<IRP_ADDRESS>
<ADDRESS_TYPE>PH</ADDRESS_TYPE>
</IRP_ADDRESS>
<IRP_ADDRESS>
<ADDRESS_TYPE>MA</ADDRESS_TYPE>
</IRP_ADDRESS>
</IRP_NAME>
</IRP_ACCOUNT>
</T0020>
I have given sample output with only element to save space.
I have tried below XSLT but it is not giving desire result
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/ROWSET">
<xsl:element name="T0020">
<xsl:apply-templates select="irp_account"/>
</xsl:element>
</xsl:template>
<xsl:template match="irp_account">
<xsl:element name="IRP_ACCOUNT">
<xsl:apply-templates select="IRP_CARRIER_ID_NUMBER"/>
<xsl:apply-templates select="IRP_ACCOUNT_NUMBER"/>
<xsl:apply-templates select="IRP_ACCOUNT_TYPE"/>
<xsl:apply-templates select="NAME_TYPE"/>
<xsl:apply-templates select="ADDRESS_TYPE"/>
</xsl:element>
</xsl:template>
<xsl:template match="IRP_CARRIER_ID_NUMBER">
<xsl:copy-of select="descendant-or-self::IRP_CARRIER_ID_NUMBER"/>
</xsl:template>
<xsl:template match="IRP_ACCOUNT_NUMBER">
<xsl:copy-of select="descendant-or-self::IRP_ACCOUNT_NUMBER"/>
</xsl:template>
<xsl:template match="IRP_ACCOUNT_TYPE">
<xsl:copy-of select="descendant-or-self::IRP_ACCOUNT_TYPE"/>
</xsl:template>
<xsl:template match="NAME_TYPE">
<xsl:element name="IRP_NAME">
<xsl:copy-of select="descendant-or-self::NAME_TYPE"/>
<xsl:copy-of select="following-sibling::NAME"/>
</xsl:element>
</xsl:template>
<xsl:template match="ADDRESS_TYPE">
<xsl:element name="IRP_ADDRESS">
<xsl:copy-of select="descendant-or-self::ADDRESS_TYPE"/>
<xsl:copy-of select="following-sibling::NAME"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Please help