xsl-list
[Top] [All Lists]

Re: Cannot get numeric value - what am I doing wrong?

2004-03-18 06:27:38
Kyle Partridge wrote:

Hi all,

This is probably an easy question for you to answer, but I'm stumped.

I've got this variable I'm trying to assign a NUMERIC value to:

Unless you are doing a xsl:value-of (or a few other things), you are getting back nodes from xpath expressions. You can call /my/path/to/node/text() to get the actual value in xpath format.

You can also do <xsl:value-of select="sum(/my/path/to/number)"/>
To return the sum off all numbers in the 'number' nodes.


<xsl:variable name="top-remove">
        <xsl:choose>
                <xsl:when test="string($prior-break-regions)">
                        <xsl:call-template name="add-up">
                                <xsl:with-param name="set-one"
select="$prior-break-regions/@top"/>
                                <xsl:with-param name="set-two"
select="$prior-break-regions/@height"/>
                        </xsl:call-template>
                </xsl:when>
                <xsl:otherwise><xsl:value-of
select="number('0')"/></xsl:otherwise>
        </xsl:choose>
</xsl:variable>

It calls a template, "add-up" which takes two sets of number node-sets
and adds them all together.  This, too, is supposed to return a NUMERIC
value:

<xsl:template name="add-up">
        <xsl:param name="set-one"/>
        <xsl:param name="set-two"/>
        <xsl:param name="index" select="1"/>
        <xsl:param name="total" select="0"/>
        <xsl:choose>
                <xsl:when test="$index &gt; count($set-one) or $index
&gt; count($set-two)">
                        <xsl:value-of select="number($total)"/>
                </xsl:when>
                <xsl:otherwise>
                        <xsl:call-template name="add-up">
                                <xsl:with-param name="set-one"
select="$set-one"/>
                                <xsl:with-param name="set-two"
select="$set-two"/>
                                <xsl:with-param name="total"
select="$total + $set-one[$index] + $set-two[$index]"/>
                                <xsl:with-param name="index"
select="$index + 1"/>
                        </xsl:call-template>
                </xsl:otherwise>
        </xsl:choose>
</xsl:template>

So...HOW COME I wind up with a Node-Fragment type assigned to my
variable, when all is said and done???  I need the value to be a numeric
value, so that when I test to see if it is boolean true or false, it
will react properly.

Thanks,
KP


XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



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