使用xsl格式化Xml节点

时间:2013-04-06 05:53:17

标签: xml xslt

我初学xsl,格式化节点(即UnitCost)值有问题。

我想要节点UnitCost Value ie; 5.0000(小数点后4个零)使用xsl在小数点后仅2个零。

Xml文件:

  <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/>
....

从xml文件中读取UnitCost

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

任何帮助都是明白的。

1 个答案:

答案 0 :(得分:2)

尝试使用format-number()功能:

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