The first part, dividing the two (so-called) attributes is easy:
RECORDITEM[(_at_)sqlsource='oldshares'] div
RECORDITEM[(_at_)sqlsource='newshares']
The next bit is more difficult. There's no built-in function (like sum())
that takes the product of a set of numbers, but Dimitre's FXSL library makes
it very easy to define one of your own. If he's listening, I'm sure he'll
tell you how.
The alternative is to do a recursive scan of the values: write a template
(or XSLT 2.0 function) that takes a RECORDSECTION as an argument and the
product-so-far as a second argument. Compute the value above, multiply it by
the product-so-far, and call the template with the following-sibling
RECORDSECTION and the new product as the arguments. Start the thing off by
calling this template/function with the first RECORDSECTION and the value 1
as arguments, terminate the recursion when there are no following siblings.
Michael Kay
http://www.saxonica.com/
-----Original Message-----
From: Whitney, Dan (CanWest Interactive)
[mailto:DWhitney(_at_)canwest(_dot_)com]
Sent: 13 April 2005 13:58
To: 'mulberry - xsl'
Subject: [xsl] params - keys? how to calculate product of
parents with multiple children
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[(_at_)sqlsource='newshares'] div
RECORDSECTION[1]/RECORDITEM[(_at_)sqlsource='oldshares']"/>
<xsl:variable name="product[position()]"
select="RECORDSECTION[2]/RECORDITEM[(_at_)sqlsource='newshares'] div
RECORDSECTION[1]/RECORDITEM[(_at_)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()
> 1]"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template match="ID"/>
</xsl:stylesheet>
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--