xsl-list
[Top] [All Lists]

[xsl] XSL 1.0 - sum values taken from corresponding column

2015-02-12 05:42:39
Hello,

In <col2>, where cell = num, return the corresponding col1/cell/@value,
summing the result.

<root>
        <col1>
                <cell value="1">text</cell>
                <cell value="12">text</cell>
                <cell value="24">text</cell>
                <cell value="100">text</cell>
                <cell value="9">text</cell>
                <cell value="6">text</cell>
        </col1>
        <col2>
                <cell>num</cell>
                <cell>-</cell>
                <cell>num</cell>
                <cell>-</cell>
                <cell>num</cell>
                <cell>num</cell>
        </col2>
        <col3>
                <cell>-</cell>
                <cell>num</cell>
                <cell>num</cell>
                <cell>num</cell>
                <cell>num</cell>
                <cell>-</cell>
        </col3>
</root>

Sum for <col2> is: 40

Sum for <col3> is: 145

I'd like an XPath solution, but I don't think that is possible.

I tried using keys.

<xsl:key name="byValue" match="cell" use="/root/col1/cell[position() =
count(current()/preceding-sibling::cell)+1]/@value"/>

So each cell has the correct value, but I'm struggling to sum the values.
Maybe my thinking is wrong.

Any help appreciated.

--
Kevin
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>