Copied to clipboard

Flag this post as spam?

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


  • AlexR 39 posts 61 karma points
    May 24, 2010 @ 07:04
    AlexR
    0

    How to call template with list of numbers as parameter value

    I writed template that return maxNumer.

    <xsl:template name="selectMaxNumber">
      <xsl:param name="numbers" />
      <xsl:for-each select="$numbers">
    <xsl:sort data-type="number" order="descending" />
        <xsl:if test="position() = 1"><xsl:value-of select="."/></xsl:if>
      </xsl:for-each>
    </xsl:template>

     

    But I can not call this template/ I can not send parameter as numbers list.

    For example, the next code return error

         <xsl:call-template name="selectMaxNumber">
            <xsl:with-param name="numbers" select="$rootFolder/node/@nodeName" />
          </xsl:call-template>

     

    The node names is years so it is number.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    May 24, 2010 @ 10:28
    Dirk De Grave
    0

    Hi AlexR,

    Parameter "numbers" you're passing to your template is passed as a string, so you could use number($rootFolder/node/@nodeName) to get around that. But, even if you'd pass this to your template, I still can't figure out what you're trying to do with it.. you're passing a single number and using a for-each to iterate... I don't see the relation here...

    Could you elaborate on your content structure so we get a visual clue on what you're trying to achieve.

     

    Cheers,

    /Dirk

  • AlexR 39 posts 61 karma points
    May 24, 2010 @ 20:01
    AlexR
    0

    Hi Dirk,

    I want to pass list of years to selectMaxNumber template.

    For example if I have next xml

    <node nodeName="newsFolder">
      <node nodeName="2009">

    ...
      </
    node>
      <node nodeName="
    2010">
      ...
      </
    node>
    </
    node>

     

    I want to pass numbers "2009 2010" as list to parameter numbers.

    And I want get 2010 as result of selectMaxNumber template.

     

    The xpath expression "$rootFolder/node" pass correct nodes to template. But it pass nodes, not nodeNames.

    I thinked that xpath expression "$rootFolder/node/@nodeName" will pass list of nodeNames (2009 2010), but it pass only first nodeName.

    Why xpath expression "$rootFolder/node" pass list of nodes, but xpath expression "$rootFolder/node/@nodeName" pass only fist nodeName?

     

    For example

    xpath "$rootFolder/node[1]/@nodeName" return first nodeName.

    xpath "$rootFolder/node[2]/@nodeName" return second nodeName.

    so "$rootFolder/node/@nodeName" should return all nodeNames. But it doesn't.


     I want pass list of nodeNames to template. How can I make it?

     

    I know that I can rewrite selectMaxNumber template to select nodeName inside it. But I want to write universal template to select max number.

Please Sign in or register to post replies

Write your reply to:

Draft