Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 411853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:01:40+00:00 2026-05-12T18:01:40+00:00

thanks a lot for giving me response and help. My problem is in my

  • 0

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.

<Jobs> 
  <Job> 
    <Job_ID>80000000</Job_ID>  
    <PositionID>60000002</PositionID>  
    <Title>Development Manager - Investment Banking - Equities Business</Title>  
    <Summary>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.&#160;&#160; My client, a well known investment bank, requires an experienced Development Manager to join their core technology team. This t</Summary>  
    <DateActive>10/6/2009</DateActive>  
    <DateExpire>11/5/2009</DateExpire>  
    <DateUpdated>10/6/2009</DateUpdated>  
    <Country>Country</Country>  
    <State>state</State>  
    <City>city</City>  
    <PostalCode>2000</PostalCode>  
    <CompanyName>Ambition Technology</CompanyName>  
    <BuilderFields />  
    <DisplayOptions />  
    <AddressType>6</AddressType>  
  </Job> 
  <Job> 
    <Job_ID>83790557</Job_ID>  
    <PositionID>61220512</PositionID>  
    <Title>SQL/VB Analyst Programmers With Strong Client Facing Skills $60 - $80K</Title>  
    <Summary>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&#160;3 Analyst/Programmer</Summary>  
    <DateActive>10/5/2009</DateActive>  
    <DateExpire>11/4/2009</DateExpire>  
    <DateUpdated>10/5/2009</DateUpdated>  
    <Country>Australia</Country>  
    <State>NSW</State>  
    <City>Sydney</City>  
    <PostalCode>2000</PostalCode>  
    <CompanyName>Skill Quest</CompanyName>  
    <SalMin>30000</SalMin>  
    <SalMax>70000</SalMax>  
    <SalType>Per Year</SalType>  
    <SalCurrency>AUD</SalCurrency>  
    <BuilderFields />  
    <DisplayOptions />  
    <AddressType>6</AddressType>  
  </Job> 

<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
  <xsl:output method="xml" indent="yes" encoding="utf-8"
  omit-xml-declaration="no" />
  <xsl:template match="/">
    <Monster>
      <xsl:for-each select="Monster/Jobs">
        <Jobs>

          <!--<Found>
            <xsl:value-of select="@Found" />
          </Found>
          <Returned>
            <xsl:value-of select="@Returned" />
          </Returned>-->
          <xsl:for-each select="Job">
            <Job>
            <Job_ID>
              <xsl:value-of select="@ID" />
            </Job_ID>
            <PositionID>
              <xsl:value-of select="@PositionID" />
            </PositionID>
            <xsl:for-each select="Title">
              <Title>
                <xsl:apply-templates/>
              </Title>
            </xsl:for-each >
            <xsl:for-each select="Summary">
              <Summary>
                <xsl:apply-templates/>
              </Summary>
            </xsl:for-each >
            <xsl:for-each select="DateActive">
              <DateActive>
                <xsl:apply-templates/>
              </DateActive>
            </xsl:for-each >
            <xsl:for-each select="DateExpires">
              <DateExpire>
                <xsl:apply-templates/>
              </DateExpire>
            </xsl:for-each >
            <xsl:for-each select="DateUpdated">
              <DateUpdated>
                <xsl:apply-templates/>
              </DateUpdated>
            </xsl:for-each >
            <xsl:for-each select="Location/Country">
              <Country>
                <xsl:apply-templates/>
              </Country>
            </xsl:for-each >
            <xsl:for-each select="Location/State">
              <State>
                <xsl:apply-templates/>
              </State>
            </xsl:for-each>
            <xsl:for-each select="Location/City">
              <City>
                <xsl:apply-templates/>
              </City>
            </xsl:for-each>
            <xsl:for-each select="Location/PostalCode">
              <PostalCode>
                <xsl:apply-templates/>
              </PostalCode>
            </xsl:for-each>
            <xsl:for-each select="CompanyName">
              <CompanyName>
                <xsl:apply-templates/>
              </CompanyName>
            </xsl:for-each>

  <xsl:for-each select="Salary/Min">             
                <SalMin>
                  <xsl:value-of select="@Value" />
                </SalMin>                          
            </xsl:for-each >
            <xsl:for-each select="Salary/Max">
              <SalMax>
                <xsl:value-of select="@Value" />
              </SalMax>
              </xsl:for-each >
            <xsl:for-each select="Salary/Type">
              <SalType>
                <xsl:apply-templates/>
              </SalType>
            </xsl:for-each >
            <xsl:for-each select="Salary/Currency">
              <SalCurrency>
                <xsl:apply-templates/>
              </SalCurrency>
            </xsl:for-each >
            <xsl:for-each select="BuilderFields">
              <BuilderFields>
                <xsl:apply-templates/>
              </BuilderFields>
            </xsl:for-each >
            <xsl:for-each select="DisplayOptions">
              <DisplayOptions>
                <xsl:apply-templates/>
              </DisplayOptions>
            </xsl:for-each >
            <xsl:for-each select="AddressType">
              <AddressType>
                <xsl:apply-templates/>
              </AddressType>
            </xsl:for-each >
              <xsl:call-template name="ApplyTemplatesOrCreate">
                <xsl:with-param name="elemName" select="'SalMin'" />
                <xsl:with-param name="elemDefault" select="'0'" />
              </xsl:call-template>
            </Job>
            <!--Closing-->
          </xsl:for-each >
        </Jobs >
      </xsl:for-each >
    </Monster>
  </xsl:template>




  <xsl:template name="ApplyTemplatesOrCreate">
    <xsl:param name="elemName" select="'SalMin'" />
    <xsl:param name="elemDefault" select="'0'" />

    <xsl:variable name="elem" select="*[name() = $elemName]" />

    <xsl:choose>
      <xsl:when test="$elem">
        <xsl:apply-templates select="$elem" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:if test="$elemName != ''">
          <xsl:element name="{$elemName}">
            <xsl:value-of select="$elemDefault" />
          </xsl:element>
        </xsl:if>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

</xsl:stylesheet >

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T18:01:40+00:00Added an answer on May 12, 2026 at 6:01 pm

    Since you didn’t post your XSL before, we couldn’t tell that the example XML was actually the output of your stylesheet and not the input. The quickest and dirtiest way to fix for these required elements would be to add a check for whether the input element existed:

            <xsl:for-each select="Salary/Max">
              <SalMax>
                <xsl:value-of select="@Value" />
              </SalMax>
            </xsl:for-each >
            <xsl:if test="not(Salary/Max/@Value)">
              <SalMax>0</SalMax>
            </xsl:if>
    

    A little better would be to output the required element and then do the check inside:

          <SalMax>
            <xsl:value-of select="Salary/Max/@Value" />
            <xsl:if test="not(Salary/Max/@Value)">0</xsl:if>
          </SalMax>
    
          <SalType>
            <xsl:apply-templates select="Salary/Type" />
            <xsl:if test="not(Salary/Type)">NO_TYPE</xsl:if>
          </SalType>
    

    You could write a template to call, similar to Tomalak’s, so you wouldn’t have to duplicate the xpath expression or the logic:

        <SalType>
            <xsl:call-template name="ApplyTemplatesOrDefault">
                <xsl:with-param name="elem" select="Salary/Type"/>
                <xsl:with-param name="default">NO_TYPE</xsl:with-param>
            </xsl:call-template>
        </SalType>
    

    …

        <xsl:template name="ApplyTemplatesOrDefault">
            <xsl:param name="elem" />
            <xsl:param name="default" select="0"/>
    
            <xsl:choose>
                <xsl:when test="$elem">
                    <xsl:apply-templates select="$elem" />
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="$default" />
                </xsl:otherwise>
            </xsl:choose>
        </xsl:template>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This problem has been solved! Thanks a lot to Brad, Denis and junkie! You're
How to explicitly set django_language in Django session? Thanks a lot...
Thanks for the help on here with my query on here the other day
Thanks to some help I received yesterday I've got some dynamic summing working on
Thanks in advance for your help. I have a need within an application to
EDIT: thanks a lot for all the answers an points raised. As a novice
I have a problem with giving a template class a template friend in Sun
This is giving me quite some headache. I have an page-tab-application, where DB-interaction uses
i'm doing a simple parse of some JSON and it's giving me an error
here is the html code that is giving me problem in IE7 <div style=position:absolute;top:276px;left:194px;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.