title: Creating empty element if not exists
body: <p>thanks a lot for giving me response and help. My problem is in my xml file some elements are missing in some xml set and in some other they exists. So, if these elements are not exists i want to create only elements with value 0. Earlier i got answer from the well known advisor, which i have implements but not getting the required output may be i am doing wrong implementation. Pls. help me. I want to Add new elements Like SalMin,SalMax,SalType and SalCurrency while transformation of xml file. Below follows the xml file and xslt file.</p>
  
  <pre><code>&lt;Jobs&gt; 
    &lt;Job&gt; 
      &lt;Job_ID&gt;80000000&lt;/Job_ID&gt;  
      &lt;PositionID&gt;60000002&lt;/PositionID&gt;  
      &lt;Title&gt;Development Manager - Investment Banking - Equities Business&lt;/Title&gt;  
      &lt;Summary&gt;An experienced Development Manager with previous experience leading a small to mid-size team of developers in a Java/J2EE environment. A hands on role, you will be expected to manage and mentor a team of developers working on a mix of greenfield and maintenance projects.&amp;#160;&amp;#160; My client, a well known investment bank, requires an experienced Development Manager to join their core technology team. This t&lt;/Summary&gt;  
      &lt;DateActive&gt;10/6/2009&lt;/DateActive&gt;  
      &lt;DateExpire&gt;11/5/2009&lt;/DateExpire&gt;  
      &lt;DateUpdated&gt;10/6/2009&lt;/DateUpdated&gt;  
      &lt;Country&gt;Country&lt;/Country&gt;  
      &lt;State&gt;state&lt;/State&gt;  
      &lt;City&gt;city&lt;/City&gt;  
      &lt;PostalCode&gt;2000&lt;/PostalCode&gt;  
      &lt;CompanyName&gt;Ambition Technology&lt;/CompanyName&gt;  
      &lt;BuilderFields /&gt;  
      &lt;DisplayOptions /&gt;  
      &lt;AddressType&gt;6&lt;/AddressType&gt;  
    &lt;/Job&gt; 
    &lt;Job&gt; 
      &lt;Job_ID&gt;83790557&lt;/Job_ID&gt;  
      &lt;PositionID&gt;61220512&lt;/PositionID&gt;  
      &lt;Title&gt;SQL/VB Analyst Programmers With Strong Client Facing Skills $60 - $80K&lt;/Title&gt;  
      &lt;Summary&gt;Excellent Location New Technologies Career Potential My client is a fast paced  IT company in Consultancy based in Inner West of Sydney. My client is experiencing a large amount of growth due to new exciting projects which they have won due to their impressive reputation and quality of work. Due to the large amount of growth my client is experiencing they are looking to take on&amp;#160;3 Analyst/Programmer&lt;/Summary&gt;  
      &lt;DateActive&gt;10/5/2009&lt;/DateActive&gt;  
      &lt;DateExpire&gt;11/4/2009&lt;/DateExpire&gt;  
      &lt;DateUpdated&gt;10/5/2009&lt;/DateUpdated&gt;  
      &lt;Country&gt;Australia&lt;/Country&gt;  
      &lt;State&gt;NSW&lt;/State&gt;  
      &lt;City&gt;Sydney&lt;/City&gt;  
      &lt;PostalCode&gt;2000&lt;/PostalCode&gt;  
      &lt;CompanyName&gt;Skill Quest&lt;/CompanyName&gt;  
      &lt;SalMin&gt;30000&lt;/SalMin&gt;  
      &lt;SalMax&gt;70000&lt;/SalMax&gt;  
      &lt;SalType&gt;Per Year&lt;/SalType&gt;  
      &lt;SalCurrency&gt;AUD&lt;/SalCurrency&gt;  
      &lt;BuilderFields /&gt;  
      &lt;DisplayOptions /&gt;  
      &lt;AddressType&gt;6&lt;/AddressType&gt;  
    &lt;/Job&gt; 
  </code></pre>
  
  <h2>    </h2>
  
  <pre><code>&lt;?xml version="1.0" ?&gt;
  &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0"&gt;
    &lt;xsl:output method="xml" indent="yes" encoding="utf-8"
    omit-xml-declaration="no" /&gt;
    &lt;xsl:template match="/"&gt;
      &lt;Monster&gt;
        &lt;xsl:for-each select="Monster/Jobs"&gt;
          &lt;Jobs&gt;
  
            &lt;!--&lt;Found&gt;
              &lt;xsl:value-of select="@Found" /&gt;
            &lt;/Found&gt;
            &lt;Returned&gt;
              &lt;xsl:value-of select="@Returned" /&gt;
            &lt;/Returned&gt;--&gt;
            &lt;xsl:for-each select="Job"&gt;
              &lt;Job&gt;
              &lt;Job_ID&gt;
                &lt;xsl:value-of select="@ID" /&gt;
              &lt;/Job_ID&gt;
              &lt;PositionID&gt;
                &lt;xsl:value-of select="@PositionID" /&gt;
              &lt;/PositionID&gt;
              &lt;xsl:for-each select="Title"&gt;
                &lt;Title&gt;
                  &lt;xsl:apply-templates/&gt;
                &lt;/Title&gt;
              &lt;/xsl:for-each &gt;
              &lt;xsl:for-each select="Summary"&gt;
                &lt;Summary&gt;
                  &lt;xsl:apply-templates/&gt;
                &lt;/Summary&gt;
              &lt;/xsl:for-each &gt;
              &lt;xsl:for-each select="DateActive"&gt;
                &lt;DateActive&gt;
                  &lt;xsl:apply-templates/&gt;
                &lt;/DateActive&gt;
              &lt;/xsl:for-each &gt;
              &lt;xsl:for-each select="DateExpires"&gt;
                &lt;DateExpire&gt;
                  &lt;xsl:apply-templates/&gt;
                &lt;/DateExpire&gt;
              &lt;/xsl:for-each &gt;
              &lt;xsl:for-each select="DateUpdated"&gt;
                &lt;DateUpdated&gt;
                  &lt;xsl:apply-templates/&gt;
                &lt;/DateUpdated&gt;
              &lt;/xsl:for-each &gt;
              &lt;xsl:for-each select="Location/Country"&gt;
                &lt;Country&gt;
                  &lt;xsl:apply-templates/&gt;
                &lt;/Country&gt;
              &lt;/xsl:for-each &gt;
              &lt;xsl:for-each select="Location/State"&gt;
                &lt;State&gt;
                  &lt;xsl:apply-templates/&gt;
                &lt;/State&gt;
              &lt;/xsl:for-each&gt;
              &lt;xsl:for-each select="Location/City"&gt;
                &lt;City&gt;
                  &lt;xsl:apply-templates/&gt;
                &lt;/City&gt;
              &lt;/xsl:for-each&gt;
              &lt;xsl:for-each select="Location/PostalCode"&gt;
                &lt;PostalCode&gt;
                  &lt;xsl:apply-templates/&gt;
                &lt;/PostalCode&gt;
              &lt;/xsl:for-each&gt;
              &lt;xsl:for-each select="CompanyName"&gt;
                &lt;CompanyName&gt;
                  &lt;xsl:apply-templates/&gt;
                &lt;/CompanyName&gt;
              &lt;/xsl:for-each&gt;
  
    &lt;xsl:for-each select="Salary/Min"&gt;             
                  &lt;SalMin&gt;
                    &lt;xsl:value-of select="@Value" /&gt;
                  &lt;/SalMin&gt;                          
              &lt;/xsl:for-each &gt;
              &lt;xsl:for-each select="Salary/Max"&gt;
                &lt;SalMax&gt;
                  &lt;xsl:value-of select="@Value" /&gt;
                &lt;/SalMax&gt;
                &lt;/xsl:for-each &gt;
              &lt;xsl:for-each select="Salary/Type"&gt;
                &lt;SalType&gt;
                  &lt;xsl:apply-templates/&gt;
                &lt;/SalType&gt;
              &lt;/xsl:for-each &gt;
              &lt;xsl:for-each select="Salary/Currency"&gt;
                &lt;SalCurrency&gt;
                  &lt;xsl:apply-templates/&gt;
                &lt;/SalCurrency&gt;
              &lt;/xsl:for-each &gt;
              &lt;xsl:for-each select="BuilderFields"&gt;
                &lt;BuilderFields&gt;
                  &lt;xsl:apply-templates/&gt;
                &lt;/BuilderFields&gt;
              &lt;/xsl:for-each &gt;
              &lt;xsl:for-each select="DisplayOptions"&gt;
                &lt;DisplayOptions&gt;
                  &lt;xsl:apply-templates/&gt;
                &lt;/DisplayOptions&gt;
              &lt;/xsl:for-each &gt;
              &lt;xsl:for-each select="AddressType"&gt;
                &lt;AddressType&gt;
                  &lt;xsl:apply-templates/&gt;
                &lt;/AddressType&gt;
              &lt;/xsl:for-each &gt;
                &lt;xsl:call-template name="ApplyTemplatesOrCreate"&gt;
                  &lt;xsl:with-param name="elemName" select="'SalMin'" /&gt;
                  &lt;xsl:with-param name="elemDefault" select="'0'" /&gt;
                &lt;/xsl:call-template&gt;
              &lt;/Job&gt;
              &lt;!--Closing--&gt;
            &lt;/xsl:for-each &gt;
          &lt;/Jobs &gt;
        &lt;/xsl:for-each &gt;
      &lt;/Monster&gt;
    &lt;/xsl:template&gt;
  
  
  
  
    &lt;xsl:template name="ApplyTemplatesOrCreate"&gt;
      &lt;xsl:param name="elemName" select="'SalMin'" /&gt;
      &lt;xsl:param name="elemDefault" select="'0'" /&gt;
  
      &lt;xsl:variable name="elem" select="*[name() = $elemName]" /&gt;
  
      &lt;xsl:choose&gt;
        &lt;xsl:when test="$elem"&gt;
          &lt;xsl:apply-templates select="$elem" /&gt;
        &lt;/xsl:when&gt;
        &lt;xsl:otherwise&gt;
          &lt;xsl:if test="$elemName != ''"&gt;
            &lt;xsl:element name="{$elemName}"&gt;
              &lt;xsl:value-of select="$elemDefault" /&gt;
            &lt;/xsl:element&gt;
          &lt;/xsl:if&gt;
        &lt;/xsl:otherwise&gt;
      &lt;/xsl:choose&gt;
    &lt;/xsl:template&gt;
  
  &lt;/xsl:stylesheet &gt;
  </code></pre>
  
  <p>Pls. get me a solution, earlier Mr. Tomalak helped me a lot, even i told him i will get a solution by implemention his suggested code, but i am doing somewhere wrong.</p>