Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Multiply ancestors in xsl

From: martinpettersson1974@-------.--- (------ ----------)
To: NULL
Date: 10/18/2004 2:14:00 AM
"Joris Gillis" <roac@p...> wrote in message news:<opsfeypij8yf9v9r@n...>...
> 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) &gt; 0">
>    <xsl:call-template name="multiply">
>    <xsl:with-param name="product" select="$product * $values[1]"/>
>    <xsl:with-param name="values" select="$values[position() &gt; 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

Hi Joris,

Finally I tried to incorporate your template with my code. Perfect, it
works fine. Thank you.

I share your view of how the document is structured. Not much I can do
about it =).

Martin Pettersson


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent