473,804 Members | 3,705 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiply ancestors in xsl

Hi all,

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.

The files are pasted below. First I have tried to find these values,
the next step will be to start the calculation

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

I will really appreciate all kind of feedback on this.

All the best,
Martin
XML:

<?xml-stylesheet type="text/xsl" href="C:\xml-xsl\realized-by.xsl"?>
<state>
<part name="part_5990 157" no="1">
<attributes>
<attribute name="qty">1</attribute>
</attributes>
<subparts>
<part name="support_b eam_horizontal_ part" no="1">
<attributes>
<attribute name="qty">1</attribute>
</attributes>
<subparts>
<part name="endcap_pa rt" no="1">
<attributes>
<attribute name="qty">4</attribute>
</attributes>
<subparts/>
<realized-by>
<name>a_xcbe_44 x88</name>
<desc>XCBE 44X88</desc>
</realized-by>
</part>
<part name="support_b racket_part" no="1">
<attributes>
<attribute name="qty">6</attribute>
</attributes>
<subparts>
<part name="nut_1_par t" no="1">
<attributes>
<attribute name="qty">4</attribute>
</attributes>
<subparts/>
<realized-by>
<name>a_xlaq_ 8</name>
<desc>XLAQ 8</desc>
</realized-by>
</part>
<part name="bolt_2_pa rt" no="1">
<attributes>
<attribute name="qty">3</attribute>
</attributes>
<subparts/>
<realized-by>
<name>a_m6s_8x1 6</name>
<desc>M6S 8X16</desc>
</realized-by>
</part>
</subparts>
<realized-by>
<name>a_xlct_21 x158_r</name>
<desc>XLCT 21X158 R </desc>
</realized-by>
</part>
</subparts>
<realized-by>
<name>a_xcbl_lx 88</name>
<desc>XCBL LX88</desc>
</realized-by>
</part>
</subparts>
<realized-by>
<name>_599013 3</name>
<desc>XCUF T02X88 A</desc>
</realized-by>
</part>
</state>
XSL:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
<html>
<body>
<table border="2" bordercolor="bl ack">
<tr>
<td>Qty</td>
<td>Parent Qty</td>
<td>No of ancestors</td>
</tr>
<xsl:for-each select="//part">
<xsl:for-each select="*/*/realized-by">
<xsl:if test="not(conta ins(../@name,'dummy')) ">
<tr>
<td>
<xsl:value-of select="../*/*[@name='qty']"/>
</td>
<td>
<xsl:value-of select="parent: :part/*/*[@name='qty']"/>
</td>
<td>
<xsl:value-of select="count(a ncestor::*/@name)"/>
</td>
</tr>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
<!-- Parts - end -->
<tr>
<td height="10" colspan="4"/>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Jul 20 '05 #1
2 3097
On 5 Oct 2004 00:56:12 -0700, Martin Pettersson
<ma************ ******@hotmail. com> 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="ancesto r::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($va lues) &gt; 0">
<xsl:call-template name="multiply" >
<xsl:with-param name="product" select="$produc t * $values[1]"/>
<xsl:with-param name="values" select="$values[position() &gt; 1]"/>
</xsl:call-template>
</xsl:if>
<xsl:if test="count($va lues)=0">
<xsl:value-of select="$produc t"/>
</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
Jul 20 '05 #2
"Joris Gillis" <ro**@pandora.b e> wrote in message news:<op******* *******@news.pa ndora.be>...
On 5 Oct 2004 00:56:12 -0700, Martin Pettersson
<ma************ ******@hotmail. com> 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="ancesto r::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($va lues) &gt; 0">
<xsl:call-template name="multiply" >
<xsl:with-param name="product" select="$produc t * $values[1]"/>
<xsl:with-param name="values" select="$values[position() &gt; 1]"/>
</xsl:call-template>
</xsl:if>
<xsl:if test="count($va lues)=0">
<xsl:value-of select="$produc t"/>
</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
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3387
by: yurick | last post by:
Hello everybody, I'm quit newbie to XML/XSLT, would appreciate any help. There is XML like this: <person name="adam"/> <person name="eve"/> <person name="cain"> <parent name="adam"/>
15
13283
by: christopher diggins | last post by:
Here is some code I wrote for Matrix multiplication for arbitrary dimensionality known at compile-time. I am curious how practical it is. For instance, is it common to know the dimensionality of matricies at compile-time? Any help would be appreciated. Hopefully this code comes in useful for someone, let me know if you find it useful, or if you have suggestions on how to improve it. // Public Domain by Christopher Diggins, 2005 ...
4
7248
by: trint | last post by:
Why do we have to use decimal.multiply to multiply two intgers? I just want to multiply these two values: int oneThousand = 1000; int watCHTimer1 = value from a textbox; Thanks, Trint
11
2538
by: vips | last post by:
I have a string str="10*12*14" now I want the total of this value i.e. 10 multiply 12 multiply 14 how do i get it ? is there any function in vb.net to do that ?? if i put it as query to database I get the result, but I want to do it in the code.
0
4002
by: komandjaja | last post by:
Hi everybody. I am new here and I don't know much about CSS. However, I have a blog at multiply http://komandjaja.multiply.com and I have customized the CSS codes there to make a new theme. When I see my page thru Firefox, everything is okay but when I see it with IE, there are distorted things and some pictures don't show up. My platform is Windows XP home edition. Here's my css code to the site /************* Spiderman 3...
4
8031
by: Yanick | last post by:
Is it possible, with JQuery to get only one specific element ancestor ? For example : <div> <ul id="tree"> <li><a>Item 1</a> <ul id="subTree"> <li><a>Item 1.1</a></li> </ul> </li>
12
2101
by: Janaka Perera | last post by:
Hi All, We have done a object oriented design for a system which will create a class multiply inherited by around 1000 small and medium sized classes. I would be greatful if you can help me with the following: Can this create any problems with GNU g++ compilation, linking etc? What would be the impact to the performance of the system? Anything else we have to consider?
2
1091
by: andrew cooke | last post by:
Hi, I am seeing some odd behaviour with logging which would be explained if loggers that are not defined explicitly (but which are controlled via their ancestors) must be created after the logging system is configured via fileConfig(). That's a bit abstract, so here's the problem itself: I define my log within a module by doing
1
1993
by: Gavin Chen | last post by:
Hello: I tried to install Tk800.015 on SunOS 4.1.4 with perl 5.6.2. At "make test" time, I got the error message as below: collect2: ld returned 2 exit status ld: /usr/local/lib/perl5/site_perl/5.6.2/sun4-sunos/auto/Tk/Event/Event.a(Event.o): _LangExit: multiply defined ld: /usr/local/lib/perl5/site_perl/5.6.2/sun4-sunos/auto/Tk/Event/Event.a(Event.o): _Tcl_Free: multiply defined ld:...
0
10568
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10074
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9138
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7613
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6847
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5516
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4292
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2988
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.