tags:

views:

27

answers:

1

Below is the actual xml

<?xml version="1.0" encoding="utf-8"?>
<employee>
 <Name>ABC</Name>
 <Dept>CS</Dept>
 <Designation>sse</designation>
</employee>

And i want the output as below:

<?xml version="1.0" encoding="utf-8"?>
<employee>
 <Name>ABC</Name>
  <Age>34</Age>
 <Dept>CS</Dept>
  <Domain>Insurance</Domain>
 <Designation>sse</designation>
</employee>

Is this possible to add XML element in between using xslt ? Please give me sample

+1  A: 

Here is an XSLT 1.0 stylesheet that will do what you asked:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
   <!-- Identity transform -->
   <xsl:template match="@* | node()">
      <xsl:copy>
         <xsl:apply-templates select="@* | node()"/>
      </xsl:copy>
   </xsl:template>

   <xsl:template match="Name">
      <xsl:copy-of select="."/>
      <Age>34</Age>
   </xsl:template>

   <xsl:template match="Dept">
      <xsl:copy-of select="."/>
      <Domain>Insurance</Domain>
   </xsl:template>
</xsl:stylesheet>

Obviously the logic will vary depending on where you will be getting the new data from, and where it needs to go. The above stylesheet merely inserts an <Age> element after every <Name> element, and a <Domain> element after every <Dept> element.

LarsH