0

Hello guys, I have a problem convrting to an int in xslt.

My xslt is:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  xmlns:tem="http://tempuri.org/">
          <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
          <xsl:template match="/">
          <xsl:call-template name="ConnectConsumer"/>
          </xsl:template>
          <xsl:template name="ConnectConsumer">
          <tem:callRule>
          <xsl:for-each select="/">
          <xsl:for-each select="ConsumerDetails">
          <xsl:for-each select="Score">
              <xsl:element name="tem:arg0">
               <xsl:value-of select='format-number(Score,"#" )'/>
              </xsl:element>
          </xsl:for-each>
          </xsl:for-each>
          </xsl:for-each>
          </tem:callRule>
          </xsl:template>
          </xsl:stylesheet>

My xml is:

<ConsumerDetails>
        <BirthDate>1981-05-22</BirthDate>
        <Gender>Male</Gender>
        <AgeOfOldestOpenAccount>8</AgeOfOldestOpenAccount>
        <AgeOfYoungesttOpenAccount>2</AgeOfYoungesttOpenAccount>
        <TotalAccBalance24Months>50000.0</TotalAccBalance24Months>
        <AccountsWorthStatus3in24Months>4</AccountsWorthStatus3in24Months>
        <Score>849.0000</Score>
        <Age>31</Age>
        <City>MILNERTON</City>
</ConsumerDetails>

when I transform it does not work, it returns the following result:

<?xml version="1.0" encoding="UTF-8"?>
<tem:callRule xmlns:tem="http://tempuri.org/">
   <tem:arg0>NaN</tem:arg0>
</tem:callRule>

I want the number instead of NaN

2
Contributors
1
Reply
2
Views
4 Years
Discussion Span
Last Post by Mike Askew
0
          <xsl:for-each select="Score">
            <xsl:element name="tem:arg0">
              <xsl:value-of select='format-number(.,"#" )'/>
            </xsl:element>
          </xsl:for-each>

You've already selected score in the for-each and so it is looked for a child of score called score, changing this to . means it selects current which is in fact the value you are looking for :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.