Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Scope of xsl:parameter

 
ZEESHAN AZIZ
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
xsl:parameter and xsl:variable?
In one of online tests, I came acorss a question
"what is the scope of the xsl:variable & xsl:param"
I am not clear about the scope.
(Map disabled smiles)
[ July 17, 2002: Message edited by: Mapraputa Is ]
 
Vasudha Deepak
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scope of a variable depends where it is declared.
If it is declared outside of any template then it is a global variable,else if declared inside a template,then it is a local variable and is available only within the template it is declared.
 
Mapraputa Is
Leverager of our synergies
Sheriff
Posts: 10065
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
xsl:variable and xsl:param
Both can be defined inside template, or be a top-level element - i.e. defined as a child of xsl:stylesheet element.
but
xsl:variable is also allowed anywhere within a template where an instruction is allowed, xsl:param not. For example, you can define xsl:variable inside xsl:if element, which wont work for xsl:param.
They have very similar functionality, xsl:param is just another way to implement a variable. The main difference is that xsl:param can get its value from "the calling environment": you specify parameters when calling a stylesheet. For this technique to work, xsl:param must be a child of xsl:stylesheet element, not xsl:template.
Regarding scope, what Vasudha said is true, I would only add that in case of xsl:variable its scope can be even narrower. If it is declared inside some other instruction, like aforementioned xsl:if - then it's scope is this instruction and you cannot access the variable outside of xsl:if construction.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic