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

  • SEARCH
  • Home
  • 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 5942579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:16:24+00:00 2026-05-22T16:16:24+00:00

I’m running an xsl transition on some xml and need to be able to

  • 0

I’m running an xsl transition on some xml and need to be able to set some default values on a few tags if they appear as empty. For example, my xml has

<record>
<name>Bob</name>
<latitude>51.23645</latitude>
<longitude>-0.1254</longitude>
<rank></rank>
</record>

<record>
<name>Chantel</name>
<latitude></latitude>
<longitude></longitude>
<rank>5</rank>
</record>

and I would like to set some defaults to output:

<record>
<name>Bob</name>
<latitude>51.23645</latitude>
<longitude>-0.1254</longitude>
<rank>0</rank>
</record>

<record>
<name>Chantel</name>
<latitude>0.00</latitude>
<longitude>0.00</longitude>
<rank>5</rank>
</record>

I thought this would be straightforward but can’t seem to crack it.

Thanks in advance.

Edit: This is what I was trying to do. Still learning so just a fumble in the dark!

<xsl:template match="record">
  <xsl:when test="name()='latitude'">
    <xsl:element name="latitude">
      <xsl:choose>
        <xsl:when test="text()=''">
          <latitude>0.00</latitude>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="latitude"></xsl:value-of>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:element>
  </xsl:when>
</xsl:template>
  • 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-22T16:16:25+00:00Added an answer on May 22, 2026 at 4:16 pm

    Try this:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      version="1.0">
    
      <xsl:output method="xml" indent="yes"/>
      <xsl:template match="@*|node()">
        <xsl:copy>
          <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
      </xsl:template>
      <xsl:template match="rank[not(text())]">
        <xsl:copy>
          <xsl:apply-templates select="@*"/>
          <xsl:text>0</xsl:text>
        </xsl:copy>
      </xsl:template>
      <xsl:template match="latitude[not(text())]|longitude[not(text())]">
        <xsl:copy>
          <xsl:apply-templates select="@*"/>
          <xsl:text>0.00</xsl:text>
        </xsl:copy>
      </xsl:template>
    </xsl:stylesheet>
    

    Add more templates to set default values for other tags.

    How it works: The first template is known as the “identity template”, and copies nodes from input to output unchanged. The second template matches “rank” nodes without text child nodes (i.e. empty “rank” nodes), copies them to the output with their attributes and then inserts the default.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my XML file chapters tag has more chapter tag.i need to display chapters
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I need to clean up various Word 'smart' characters in user input, including but

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.