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 6060233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:48:08+00:00 2026-05-23T08:48:08+00:00

I have some XML which features a fair number of attributes in each element,

  • 0

I have some XML which features a fair number of attributes in each element, and sometimes I need to format one or two attributes if some condition is met. I thought I’d do this with XSL.

So inside my template in the XSL file I have the following:

<xsl:choose>
  <xsl:when test="ytd &lt; 0.000000001 or interest &lt; 0.000000001">
    <xsl:element name="Report">
      <xsl:choose>
        <xsl:when test="ytd&lt; 0.000000001">
          <xsl:element name="ytd">0</xsl:element>
        </xsl:when>
        <xsl:when test="interest &lt; 0.000000001">
          <xsl:element name="interest">0</xsl:element>
        </xsl:when>
        <xsl:otherwise>
          <xsl:copy-of select="." />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:element>
  </xsl:when>
  <xsl:otherwise>
    <xsl:copy-of select="." />
  </xsl:otherwise>
</xsl:choose>

The operations for the YTD and interest fields work as I expect them to, essentially rounding down small amounts to zero for me. The problem is the otherwise clause; I seem to misunderstand how to use the copy-of. I want the other n attributes of a Report element to be copied over as they are in the original XML. Problem is with this current template I get output like the following for a Report which has a very small ytd:

<Report><ytd>0</ytd></Report>

So obviously I’m not copying the rest of the element properly. Any pointers?

EDIT:
A sample input XML file might be:

<Reports>
  <Report>
    <name>Bob</name>
    <account>Saver</account>
    <ytd>100</ytd>
    <interest>0.5</ytd>
    <cosigned>false</cosigned>
  </Report>
  <Report>
    <name>Steve</name>
    <account>Gold Account</account>
    <ytd>0.0000000001</ytd>
    <interest>0.0000000001</ytd>
    <cosigned>false</cosigned>
  </Report>
</Reports>

And desired output would be:

<Reports>
  <Report>
    <name>Bob</name>
    <account>Saver</account>
    <ytd>100</ytd>
    <interest>0.5</ytd>
    <cosigned>false</cosigned>
  </Report>
  <Report>
    <name>Steve</name>
    <account>Gold Account</account>
    <ytd>0</ytd>
    <interest>0</ytd>
    <cosigned>false</cosigned>
  </Report>
</Reports>

(Obviously I’m just mocking that up but hopefully you can see what I mean)

Thanks,
Dave.

  • 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-23T08:48:09+00:00Added an answer on May 23, 2026 at 8:48 am

    I think the easiest way to do what you want is:

    <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="ytd[ . &lt; 0.000000001 ] | interest[ . &lt; 0.000000001]">
            <xsl:copy>0</xsl:copy>
        </xsl:template>
    
    </xsl:stylesheet>
    
    • Use identity rule (see first template above) to copy everything as is
    • Override elements as required
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some XML which I am testing, which has set as one of
I have some XML to which I need to add a child. Using SimpleXML,
I have some XML which contains records and sub records, like this: <data> <record
I have some XML which I'm trying to search: <debts> <section id=24 description=YYYYY> <section
I have some XML files which are used to generate my webpages, however I
I have some xml files that contain text, which are displayed on my website.
I have an xml in which i have stored some html under comments like
I have some php files in a server which generate xml code in them.
I have a method which returns some xml in a memory stream private MemoryStream
Do you have some predefined set of targets which all build.xml files you create

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.