![]() |
![]() | ![]() | ![]() | Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Multiply ancestors in xsl >Thread Next - Re: Multiply ancestors in xsl Re: Multiply ancestors in xslTo: NULL Date: 10/5/2004 8:15:00 PM On 5 Oct 2004 00:56:12 -0700, Martin Pettersson <martinpettersson1974@h...> wrote: > I'm trying to multiply parent values in xsl. The thing is that I start > with a value down in the xml-structure. From that value (in my case > 'qty' value) I check the parent value and later on I will try to > multiply these values. When I have found the parent I will multiply > with its parent and so on, all the way to the top of the xml-file. > Has anyone worked with a similar case? How can I find the 'qty' value > for hte parents? Maybe there could be a better way to work with these > kind of calculations in xsl (variables or functions ...). Hi, The following method uses variables and tree-node variables. To multiple all ancestor's 'qty' attributes, use: <xsl:call-template name="multiply"> <xsl:with-param name="values" select="ancestor::part/*/*[@name='qty']"/> </xsl:call-template> This template multiplies all values found in the 'values' parameter. It must be included in the XSL. <xsl:template name="multiply"> <xsl:param name="values"/> <xsl:param name="product" select="1"/> <xsl:if test="count($values) > 0"> <xsl:call-template name="multiply"> <xsl:with-param name="product" select="$product * $values[1]"/> <xsl:with-param name="values" select="$values[position() > 1]"/> </xsl:call-template> </xsl:if> <xsl:if test="count($values)=0"> <xsl:value-of select="$product"/> </xsl:if> </xsl:template> Is this useful? Also a little question about your document structure: Why not use real attributes in stead of nodes named 'attribute'? I mean something like : <attributes @qty="4"/> Joris Gillis -- Ceterum censeo XML omnibus esse utendum | ![]() | ![]() | ![]() |
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | |||||
|
