[xsl] params - keys? how to calculate product of parents with multiple children

Subject: [xsl] params - keys? how to calculate product of parents with multiple children
From: "Whitney, Dan (CanWest Interactive)" <DWhitney@xxxxxxxxxxx>
Date: Wed, 13 Apr 2005 08:58:12 -0400
Hi am having trouble conceptualizing how/if I can calculate the following:
I want to take the children of RECORDSECTION and divide attribute value
newshares by attribute value oldshares.
I then want to multiply the results of each those calculations (there may be
0 - any number of occurrences of RECORDSECTION). So for below it would be:
(1/2)*(1/2)= 0.25

Any help/examples would be appreciated.

Dan Whitney

XML

<?xml version="1.0" encoding="windows-1252"?>
<?xml-stylesheet type="text/xsl" href="test/split_total.xsl"?>

<PUBLICATION>
<DOCUMENT source="splits" group="surveys" output="body">
<RECORD fragment="splits" recid="12129" fragid="13" product="surveys"
group="surveys" status="1"><ID idtype="fpid">12129</ID>
<RECORDSECTION docfragment="splits">
<RECORDITEM sqlsource="oldshares">2</RECORDITEM>
<RECORDITEM sqlsource="newshares">1</RECORDITEM>
</RECORDSECTION>
<RECORDSECTION docfragment="splits">
<RECORDITEM sqlsource="oldshares">2</RECORDITEM>
<RECORDITEM sqlsource="newshares">1</RECORDITEM>
</RECORDSECTION>
</RECORD>
</DOCUMENT>
</PUBLICATION>

XSL

<xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:output
    method="html"
    encoding="iso-8859-1"
    indent="yes"
    version="4.0"/>


<xsl:template match="PUBLICATION">
  <table border="0" cellpadding="2" cellspacing="2" width="410" cols="2" >
    <tr>
      <td>
      <xsl:for-each select="DOCUMENT/RECORD">
<!-- below would like to only define param once but have it increment based
on position-->
        <xsl:variable name="product[position()]"
select="RECORDSECTION[1]/RECORDITEM[@sqlsource='newshares'] div
RECORDSECTION[1]/RECORDITEM[@sqlsource='oldshares']"/>
        <xsl:variable name="product[position()]"
select="RECORDSECTION[2]/RECORDITEM[@sqlsource='newshares'] div
RECORDSECTION[1]/RECORDITEM[@sqlsource='oldshares']"/>
<!-- this was a half conceived attempt
        <xsl:for-each select="RECORDSECTION[1]">
          <xsl:call-template name="splitfactor">
            <xsl:with-param name="factor-subset"
select="following-sibling::RECORDSECTION"/>
          </xsl:call-template>)
        </xsl:for-each>
-->
<!-- here don't even know how I would write this -->
        <xsl:value-of select="$product1 * $product2"/>
      </xsl:for-each>
      </td>
    </tr>
  </table>
</xsl:template>

<!-- half conceived attempt -->
<xsl:template name="splitfactor">
  <xsl:param name="factor-subset" select="1"/>
  <xsl:if test="$factor-subset[1]">
    <xsl:call-template name="splitfactor">
      <xsl:with-param name="factor-subset" select="$factor-subset[position()
&gt; 1]"/>
    </xsl:call-template>
  </xsl:if>		
</xsl:template>

<xsl:template match="ID"/>

</xsl:stylesheet>

Current Thread