Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Felix 46 posts 67 karma points
    Jul 02, 2010 @ 06:44
    Felix
    0

    XSLT - Passing nodes as a parameter to templates

    im scratching my head here, hopefully someone can help me out.

    Im trying to pass a set of nodes as a parameter to an xslt template. thats about it.

       <xsl:param name="currentPage"/>   

    <xsl:template match="/">
    <xsl:choose>
    <xsl:when test="$currentPage/@level=3">
    <xsl:call-template name="test">
    <xsl:with-param name="nodes">
    <xsl:value-of select="$currentPage/../node" />
    </xsl:with-param>
    </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
    <xsl:call-template name="test">
    <xsl:with-param name="nodes">
    <xsl:value-of select="$currentPage/../../node" />
    </xsl:with-param>
    </xsl:call-template>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:template>

    <xsl:template name="test">
    <xsl:param name="nodes"></xsl:param>
    <xsl:value-of select="count($nodes)" />
    </xsl:template>

     

    It errors on trying to print out the count of $nodes. Due to this i cant loop through it and do what i need to do. However just outputting $nodes within the test function does output values to the page. What am i doing wrong? :S

     

    Thanks!

  • Peter Duncanson 430 posts 1360 karma points c-trib
    Jul 02, 2010 @ 11:55
    Peter Duncanson
    1

    You are using xsl:value-of which will just get the value of the node out as a string. Instead you just want to pass the node itself like so

    <xsl:call-template name="test">
     <xsl:with-param name="nodes" select="$currentPage/../node" />
    </xsl:call-template>

    Its the difference between passing the value of a node or the node itself.

    Hope that sorts it.

  • Felix 46 posts 67 karma points
    Jul 05, 2010 @ 03:17
    Felix
    0

    thanks very much Peter!

Please Sign in or register to post replies

Write your reply to:

Draft