Difference between xsl:param and xsl:variable?

  • Thread starter Karsten Weinert
  • Start date
K

Karsten Weinert

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.
 
S

Stephan Dahl

Karsten said:
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.

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
 
M

Martin Honnen

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.
 
K

Karsten Weinert

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top