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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:13:06+00:00 2026-05-17T06:13:06+00:00

I’m trying to display different information depending on incoming data. If it’s an integer,

  • 0

I’m trying to display different information depending on incoming data. If it’s an integer, I want to display just the number, if it’s a decimal, I want to use 0.00# pattern. Ya, I know, a bit mixed up, but that’s the development spec. :>

I have the following XSL for this specific section but I can’t see to get past the xsl:when error message of

“Expected end of expression, found
‘castable’. number(SAVG) –>castable
<– as xs:decimal”

<xsl:choose>
    <xsl:when test="number(SAVG) > 0">
        <xsl:choose>
            <xsl:when test="number(SAVG) castable as xs:decimal">
                <xsl:value-of select="format-number(SAVG, '###,###,##0.00#')"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="format-number(SAVG, '###,###,##0.###')"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:when>
    <xsl:when test="number(SAVG) = 0">
        <xsl:text disable-output-escaping="yes">&amp;lt;</xsl:text>1
    </xsl:when>
    <xsl:otherwise>N/A</xsl:otherwise>
</xsl:choose>

I tried looking/poking around for answers and I have tried “instance of”, I’ve tried using xsl:if, etc but I can’t seem to get this to work. Any help would be greatly appreciated.

Thanks.

From comments:

Yes, we are using 1.0. I’m sorry I’m
new to the XSL processing, how do I
glue your XSL and input to generate
the html?

  • 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-17T06:13:06+00:00Added an answer on May 17, 2026 at 6:13 am

    I. XSLT 1.0:

    There are no xs:integer and xs:decimal in the XPath 1.0 data model used by XSLT 1.0.

    Here is a code snippet that you may use:

        <xsl:choose> 
            <xsl:when test="not(floor(SAVG) = SAVG)"> 
                <xsl:value-of select="format-number(SAVG, '###,###,##0.00#')"/> 
            </xsl:when> 
            <xsl:otherwise> <!-- Integer value -->
                <xsl:value-of select="SAVG"/> 
            </xsl:otherwise> 
        </xsl:choose> 
    

    Do note: To test if a numeric value is an integer, we use the following test:

     floor($someNum) = $someNum
    

    Here is one way to do this:

    <xsl:stylesheet version="2.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:xs="http://www.w3.org/2001/XMLSchema">
     <xsl:output method="text"/>
    
     <xsl:template match="/">
      <xsl:sequence select=
       "for $num in (3, 3.14)
         return
           if($num instance of xs:integer)
             then ($num, ' is xs:integer', '&#xA;')
             else if($num instance of xs:decimal)
               then ($num, ' is xs:decimal', '&#xA;')
               else ($num, ' is something else', '&#xA;')
       "/>
     </xsl:template>
    </xsl:stylesheet>
    

    when this transformation is applied on any XML document (not used), the wanted, correct result is produced:

    3  is xs:integer 
    3.14  is xs:decimal 
    

    Or, using the format-number() function as per your example:

    <xsl:stylesheet version="2.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:xs="http://www.w3.org/2001/XMLSchema">
     <xsl:output method="text"/>
    
     <xsl:template match="/">
      <xsl:sequence select=
       "for $num in (3, 3.14)
         return
           if($num instance of xs:integer)
             then (format-number($num, '###,###,##0.###'), '&#xA;')
             else if($num instance of xs:decimal)
               then (format-number($num, '###,###,##0.00#'), '&#xA;')
               else ()
       "/>
     </xsl:template>
    </xsl:stylesheet>
    

    produces:

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I want use html5's new tag to play a wav file (currently only supported
i want to parse a xhtml file and display in UITableView. what is the
I want to construct a data frame in an Rcpp function, but when I
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
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
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small

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.