Passing node-sets as parameters?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alfred Taylor

    Passing node-sets as parameters?

    I essentially need a countif() function for xsl. Something to where I could
    do countif(node-set, condition). Rather than try to get too extreme, i
    decided to just write one for my countif() with the condition hardcoded.
    (this was also my first venture into creating "functions" )

    Pseudo-code is essentially this: Look at the current node and check the
    condition. If the condition is true, call our function again with an
    incremented count. If false, call function with the same value. Once we
    reach the end of the node set, return the counter variable. The whole time
    we're passing around a node-set and a current index.

    My problem is that i get an error when i try to index into the node-set like
    this $node-set[$index]. It looks like when i call the template and pass in
    a node-set using the select attribute, it converts that node-set into a
    string? (according to some posts i've read) So ways around that were to
    use the mxsl:node-set(). The problem is i tried that and it didn't work.
    (I'm using .NET to do the transform)

    The other question I had was if i can even index into a node set like i'm
    doing? Or maybe there's a better alternative for what i'm trying to do?

    Thanks,
    -A

    -------- CODE
    <xsl:template name="countWage sGreaterZero">
    <xsl:param name="number" />
    <xsl:param name="index" select="1"/>
    <xsl:param name="count" select="0" />
    <xsl:choose>
    <xsl:when test="$index > count($number)" >
    <xsl:value-of select="$count" />
    </xsl:when>
    <xsl:otherwis e>
    <xsl:when test="$number[$index]/@Value > 0">
    <xsl:choose>
    <xsl:variable name="recursive _result">
    <xsl:call-template name="countWage sGreaterZero">
    <xsl:with-param name="number" select="$number " />
    <xsl:with-param name="index" select="$index + 1" />
    <xsl:with-param name="count" select="$count + 1" />
    </xsl:call-template>
    </xsl:variable>
    <xsl:value-of select="$recurs ive_result" />
    </xsl:choose>
    <xsl:otherwis e>
    <xsl:variable name="recursive _result">
    <xsl:call-template name="countWage sGreaterZero">
    <xsl:with-param name="number" select="$number " />
    <xsl:with-param name="index" select="$index + 1" />
    <xsl:with-param name="count" select="$count" />
    </xsl:call-template>
    </xsl:variable>
    <xsl:value-of select="$recurs ive_result" />
    </xsl:otherwise>
    </xsl:when>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:template>


Working...