OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xml-dev] calculating list of values using variables

can anyone help.

I sent a post out before about trying to use variables, and have been trying
some code but it comes up with the error "Keyword xsl:stylesheet may not
contain PCDATA nodes."

I have a set of details which contain an amount and a quantity and i want to
calculate the total amount for each set of details. I can calculate that and
place it in a variable, but i now want to calculate the total for all the
sets of details, giving an overall amount for all the sets of details

<xsl:variable name="Items" select="//details"/>

   <xsl:variable name="TotalValue">
    <xsl:call-template name="Total">
     <xsl:with-param name="Items" select="$Items"/>
     <xsl:with-param name="RunningTotal"    select="0"/>

    Total = <xsl:value-of
    select="format-number($TotalValue, '####0.0#')"/>

 <xsl:template name="Total">
  <xsl:param name="Items"/>
  <xsl:param name="RunningTotal"/>
   <xsl:when test="not($Items)">
    <xsl:copy-of select="$RunningTotal"/>
  <xsl:variable name="CurrentTotal"
			 select="$RunningTotal + ($Items[1]/amount * $Items[1]/quantity)"/>

   <xsl:call-template name="Total">
    <xsl:with-param name="Items" select="$Items[position()>1]"/>
    <xsl:with-param name="RunningTotal" select="$CurrentTotal"/>

"then i am calling the rest of my code to generate the table by using a
template and matching on the root node. I don't know if this could be
causing a problem?

<xsl:template match="/">

i would be very grateful if anyone could see what i am doing wrong or if
there is another way to calculate the total amount