Difference between xsl:param and xsl:variable?

Discussion in 'XML' started by Karsten Weinert, Jul 4, 2004.

  1. Hi!
    Can you please explain to me the difference between a xsl:param and a
    xsl:variable? Since I can assign a value to both only once, what's the
    point? A small example would help me a lot.

    Regards,
    Karsten.
    --
    The email above is not in use. Please write to k dot weinert at gmx
    dot net.
    Karsten Weinert, Jul 4, 2004
    #1
    1. Advertising

  2. Karsten Weinert

    Stephan Dahl Guest

    Karsten Weinert wrote:

    > Hi!
    > Can you please explain to me the difference between a xsl:param and a
    > xsl:variable? Since I can assign a value to both only once, what's the
    > point? A small example would help me a lot.
    >
    > Regards,
    > Karsten.
    > --
    > The email above is not in use. Please write to k dot weinert at gmx
    > dot net.


    Hi Karsten,
    you can assign different values to xsl:param like in the following example

    ....
    <xsl:call-template name="foo">
    <xsl:with-param name="arg" select="1"/>
    </xsl:call-template>
    <xsl:call-template name="foo">
    <xsl:with-param name="arg" select="2"/>
    </xsl:call-template>
    ....
    <xsl:template name="foo">
    <xsl:param name="arg" />
    ...
    </xsl:template>

    Best regards, Stephan
    Stephan Dahl, Jul 4, 2004
    #2
    1. Advertising

  3. Karsten Weinert wrote:


    > Can you please explain to me the difference between a xsl:param and a
    > xsl:variable? Since I can assign a value to both only once, what's the
    > point? A small example would help me a lot.


    An XSLT processor allows (or should allow) you to pass external
    parameters to a transformation for the global <xsl:param> elements you
    have in your stylesheet. Check the documentation of your XSLT processor.
    And if you have an <xsl:param> element in a named template you can call
    that template and pass a parameter in with
    <xsl:call-template name="templateName">
    <xsl:with-param name="paramName" select="xpathHere" />
    </xsl:call-template>
    much like in other programming languages you declare a function with
    formal parameters and then call it with actual parameters.

    A variable is just meant to store some value.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Jul 4, 2004
    #3
  4. Thanks, Martin Honnen and Stephan Dahl for the clear explanation. I
    can use param to set default values for the stylesheet/named template,
    which may or may not be overriden. So param is more powerful than
    variable, I could use param instead of variable.

    Karsten.
    Karsten Weinert, Jul 5, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jakk
    Replies:
    4
    Views:
    12,025
  2. Geathaa
    Replies:
    2
    Views:
    680
    Geathaa
    Jul 30, 2003
  3. Replies:
    1
    Views:
    3,583
    A. Bolmarcich
    May 27, 2005
  4. ectoplasm
    Replies:
    12
    Views:
    623
    Zorro
    Jul 28, 2005
  5. Dave
    Replies:
    5
    Views:
    618
    John Bokma
    Apr 26, 2011
Loading...

Share This Page