M
Martin Pettersson
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_5990157" no="1">
<attributes>
<attribute name="qty">1</attribute>
</attributes>
<subparts>
<part name="support_beam_horizontal_part" no="1">
<attributes>
<attribute name="qty">1</attribute>
</attributes>
<subparts>
<part name="endcap_part" no="1">
<attributes>
<attribute name="qty">4</attribute>
</attributes>
<subparts/>
<realized-by>
<name>a_xcbe_44x88</name>
<desc>XCBE 44X88</desc>
</realized-by>
</part>
<part name="support_bracket_part" no="1">
<attributes>
<attribute name="qty">6</attribute>
</attributes>
<subparts>
<part name="nut_1_part" 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_part" no="1">
<attributes>
<attribute name="qty">3</attribute>
</attributes>
<subparts/>
<realized-by>
<name>a_m6s_8x16</name>
<desc>M6S 8X16</desc>
</realized-by>
</part>
</subparts>
<realized-by>
<name>a_xlct_21x158_r</name>
<desc>XLCT 21X158 R </desc>
</realized-by>
</part>
</subparts>
<realized-by>
<name>a_xcbl_lx88</name>
<desc>XCBL LX88</desc>
</realized-by>
</part>
</subparts>
<realized-by>
<name>_5990133</name>
<desc>XCUF T02X88 A</desc>
</realized-by>
</part>
</state>
XSL:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet 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="black">
<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(contains(../@name,'dummy'))">
<tr>
<td>
<xsl:value-of select="../*/*[@name='qty']"/>
</td>
<td>
<xsl:value-of select="parent:art/*/*[@name='qty']"/>
</td>
<td>
<xsl:value-of select="count(ancestor::*/@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>
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_5990157" no="1">
<attributes>
<attribute name="qty">1</attribute>
</attributes>
<subparts>
<part name="support_beam_horizontal_part" no="1">
<attributes>
<attribute name="qty">1</attribute>
</attributes>
<subparts>
<part name="endcap_part" no="1">
<attributes>
<attribute name="qty">4</attribute>
</attributes>
<subparts/>
<realized-by>
<name>a_xcbe_44x88</name>
<desc>XCBE 44X88</desc>
</realized-by>
</part>
<part name="support_bracket_part" no="1">
<attributes>
<attribute name="qty">6</attribute>
</attributes>
<subparts>
<part name="nut_1_part" 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_part" no="1">
<attributes>
<attribute name="qty">3</attribute>
</attributes>
<subparts/>
<realized-by>
<name>a_m6s_8x16</name>
<desc>M6S 8X16</desc>
</realized-by>
</part>
</subparts>
<realized-by>
<name>a_xlct_21x158_r</name>
<desc>XLCT 21X158 R </desc>
</realized-by>
</part>
</subparts>
<realized-by>
<name>a_xcbl_lx88</name>
<desc>XCBL LX88</desc>
</realized-by>
</part>
</subparts>
<realized-by>
<name>_5990133</name>
<desc>XCUF T02X88 A</desc>
</realized-by>
</part>
</state>
XSL:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet 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="black">
<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(contains(../@name,'dummy'))">
<tr>
<td>
<xsl:value-of select="../*/*[@name='qty']"/>
</td>
<td>
<xsl:value-of select="parent:art/*/*[@name='qty']"/>
</td>
<td>
<xsl:value-of select="count(ancestor::*/@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>