Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Multiply ancestors in xsl

From: martinpettersson1974@-------.--- (------ ----------)
To: NULL
Date: 10/5/2004 12:56:00 AM
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::part/*/*[@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>


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