<PartsDetail> <Id>1481</Id> <Desc>test1</Desc> <GlobDesc>test2</GlobDesc> <Price Cur="UAH">+798.27</Price> </PartsDetail>
<PartsDetail> <Id>0741</Id> <Desc>test2</Desc> <GlobDesc>test2</GlobDesc> <Price Cur="UAH">+399.14</Price> </PartsDetail>
在视图中,我用“价格”进行了一些转换(我带来了像399.14这样的视图).
我用它进行转换:
<xsl:call-template name="showNumberWithThousands">
<xsl:with-param name="value">
<xsl:call-template name="parseNumber">
<xsl:with-param name="value" select="Price"/>
</xsl:call-template>
</xsl:with-param>
</xsl:call-template>
我现在还需要拿一笔价钱.
我试着用这个:
<xsl:value-of select="sum(//Data/Paint//PartsDetail/@Price)"/>
但结果是–NNN.
据我所知,我需要在“普通视图(没有和 – )”之前转换价格,然后再将其发送到“sum”功能.
致:@ michael.hor257k
结构更复杂.
我使用你的解决方案 – 但它没有用.看起来我做错了什么
<xsl:template name="PaintSum">
<xsl:variable name="corrected-prices">
<xsl:for-each select="//CalcData/Paint/PaintDtl">
<price> <xsl:value-of select="translate(MatAmnt, '+', '')"/> </price>
</xsl:for-each>
</xsl:variable>
<sum> <xsl:value-of select="sum(exsl:node-set($corrected-prices)/price)"/> </sum>
</xsl:template>
当我使用< xsl:call-template name =“PaintSum”/>
什么都没发生.同样,进一步的模板请求也会停止工作.
我正在尝试使用:
<xsl:variable name="corrected-prices">
<xsl:for-each select="//CalcData/Paint//PaintDtl">
<price>
<xsl:value-of select="translate(MatAmnt, '+', '')"/>
</price>
</xsl:for-each>
</xsl:variable>
并在文本中添加总和:
<xsl:value-of select="sum(exsl:node-set($corrected-prices)/price)"/>
$correct-prices包含“1086.65286.75”.
我怎么能把这变成一笔钱?
解决方法:
As I understand I need transform price to “normal view (without + and
-)” before a send it to function “sum”.
这或多或少是正确的(如果数字是负数,你不想删除减号).鉴于良好的输入,例如:
XML
<root>
<PartsDetail>
<Id>1481</Id>
<Desc>test1</Desc>
<GlobDesc>test2</GlobDesc>
<Price Cur="UAH">+798.27</Price>
</PartsDetail>
<PartsDetail>
<Id>0741</Id>
<Desc>test2</Desc>
<GlobDesc>test2</GlobDesc>
<Price Cur="UAH">+399.14</Price>
</PartsDetail>
</root>
以下样式表:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common"
extension-element-prefixes="exsl">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/root">
<xsl:variable name="corrected-prices">
<xsl:for-each select="PartsDetail">
<price>
<xsl:value-of select="translate(Price, '+', '')"/>
</price>
</xsl:for-each>
</xsl:variable>
<sum>
<xsl:value-of select="sum(exsl:node-set($corrected-prices)/price)"/>
</sum>
</xsl:template>
</xsl:stylesheet>
将返回:
<?xml version="1.0" encoding="UTF-8"?>
<sum>1197.41</sum>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。