2013-04-06 111 views
0

我初學xsl,對格式化節點(即UnitCost)值有問題。使用xsl格式化Xml節點

我想要節點UnitCost的值即; 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/> 
.... 

閱讀UnitCost從XML文件

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

任何幫助appericiated ..

回答

2

嘗試使用format-number()功能:

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

感謝@致命錯誤。 – masif 2013-04-06 06:28:58