Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

<xsl:param> basics

Status
Not open for further replies.

LuckyKoen

Programmer
Feb 14, 2005
57
BE
I'm trying to get a basic understanding of xsl. I've read through a few xsl tutorials but the use of xsl:param is still unclear to me.

1) What exactly is the select attribute for.. Is placing the value in the select attribute the same as putting the value between tags like this : <xsl:param name="sum">123</xsl:param>?

2) How do you change the value of a parameter ?

3) How do you display the value ?
 
1) Yes, select is shorthand.

2) You cannot change the value of a parameter as such, it is set when you define it. They are normally used when calling a template, ie:

Code:
<xsl:call-template name="add">
  <xsl:with-param name="a" />
  <xsl:with-param name="b" />
</xsl:call-template>
Although you can have a global parameter which is defined at the top of the stylesheet. You can also add or edit parameters programmatically using addParameter methods. Some XSL processors allow you to specify parameters as command line arguments.

3) <xsl:value-of select="$sum"/>

Jon

"There are 10 types of people in the world... those who understand binary and those who don't.
 
I managed to change a parameter's value just by defining it again like this :

Code:
<xsl:param name="header" select="'Header1'"/>

<xsl:template match="/">
  [b]<xsl:param name="header" select="'Header2'"/>[/b]
  <html>
    <body>     
      <p><xsl:value-of select="$header"/></p>
    </body>
  </html>
</xsl:template>

However, when I place the the parameter inside the html tags I get an errormessage saying " transformation failed " :

Code:
<xsl:param name="header" select="'Header1'"/>

<xsl:template match="/">
  <html>
    <body>
      [b]<xsl:param name="header" select="'Header2'"/>[/b]
      <p><xsl:value-of select="$header"/></p>
    </body>
  </html>
</xsl:template>

What's the error here ?
 
Yes, Tom is right. I also think you're not overwriting the header parameter, rather creating a local parameter also named header, but I'm not sure.

Jon

"There are 10 types of people in the world... those who understand binary and those who don't.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top