masif
masif

Reputation: 4150

Formatting Xml Node using xsl

I beginner to xsl, having problem with Formatting node(ie UnitCost) value.

I want the node UnitCost Value ie; 5.0000(4 zeroes after decimal point) to only 2 zeroes after decimal point using xsl.

Xml File:

  <root>
        <item>
        <link>http://localhost/Store/tabid/62/ProdID/1/Default.aspx</link>
        <P>
        <NB_Store_ProductsInfo>
        <ProductID>1</ProductID>
        <PortalID>0</PortalID>
        <TaxCategoryID>-1</TaxCategoryID>
        <Featured>false</Featured>
        <Archived>false</Archived>
        <CreatedByUser>1</CreatedByUser>
        <CreatedDate>2010-07-10T05:04:40.233</CreatedDate>
        <IsDeleted>false</IsDeleted>
        <ProductRef />
        <Lang>en-US</Lang>
        <Summary />
        <Description>sdcvsdcsdc&amp;lt;br /&amp;gt;
        dcsdcsdcsdcsdcsdcsdcs</Description>
        <Manufacturer />
        <ProductName>Poster1</ProductName>
        <XMLData />
        <ModifiedDate>2010-07-10T05:25:48.077</ModifiedDate>
        <SEOName />
        </NB_Store_ProductsInfo>
        <M>
        <NB_Store_ModelInfo>
        <ModelID>1</ModelID>
        <ProductID>1</ProductID>
        <ListOrder>1</ListOrder>
        <UnitCost>5.0000</UnitCost>
        <Barcode/>
....

reading UnitCost from xml file

<xsl:value-of select="./P/M/NB_Store_ModelInfo/UnitCost" />

any help is appericiated..

Upvotes: 0

Views: 151

Answers (1)

FatalError
FatalError

Reputation: 54611

Try using the format-number() function:

<xsl:value-of select="format-number(./P/M/NB_Store_ModelInfo/UnitCost, '#.00')" />

Upvotes: 2

Related Questions