php - XSL - Get SUM of price -


i have xml structure like:

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

and in view, make transformation "price" (i bring view 399.14).

i use transformation:

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

also need take sum of price now. tried use this:

<xsl:value-of select="sum(//data/paint//partsdetail/@price)"/> 

but result - nan.

as understand need transform price in "normal view (without + , -)" before send function "sum".

to: @michael.hor257k

structure more complicated. use solution - didn't work. looks i'm doing wrong

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

and when use <xsl:call-template name="paintsum"/> nothing happens. similarly, further request templates stop working.

i'm trying use:

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

and add sum in text :

<xsl:value-of select="sum(exsl:node-set($corrected-prices)/price)"/> 

but output file - crashes.

$corrected-prices contains "1086.65286.75".

how can turn sum?

as understand need transform price "normal view (without + , -)" before send function "sum".

that more or less correct (you don't want remove minus sign, in case number negative). given well-formed input such as:

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> 

the following stylesheet:

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> 

will return:

<?xml version="1.0" encoding="utf-8"?> <sum>1197.41</sum> 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -