Here is a simple example of adding an element. Suppose you have the folllowing XML document
<root>
<list>
<a>aaaa</a>
<b>bbbb</b>
</list>
</root>
and you want to add an extra element <c>. The following stylesheet is one way of adding this element.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" >
<xsl:param name="ename">c</xsl:param>
<xsl:param name="evalue">cccc</xsl:param>
<xsl:output method="xml" encoding="utf-8"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="list">
<xsl:copy>
<xsl:apply-templates/>
<xsl:if test="not(c)">
<xsl:element name="{$ename}"><xsl:value-of select="$evalue"/></xsl:element>
</xsl:if>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
The output is
<root>
<list>
<a>aaaa</a>
<b>bbbb</b>
<c>cccc</c></list>
</root>