Re: xsl:variable

Subject: Re: xsl:variable
From: David Carlisle <davidc@xxxxxxxxx>
Date: Wed, 10 May 2000 15:32:11 +0100 (BST)
  <xsl:template match="/">
  <xsl:variable name="global"/>
  <!-- Other tag -->
  </xsl:template>
  Is it correct?
  Is the variable empty?

It is syntactically correct, but strange.
If you define it like that then 
a) the variable is only usable in that one template rather than in all
   of them as it would have been if you had put the xsl:variable outside
   the template and
b) It has value a result tree template that just has a root node.
   Thus acts in almost all contexts like the empty string.
   An XSL variable never changes its value once it is bound so
   this is not very useful definition for $global.


  <xsl:template match="pb">
  <xsl:variable name="global">
  <xsl:value-of select="$global"/>

This is again correct put again strange.
You have defined another variable (also called global)
that is local to this template, and again defined it to be empty.

  Another question why the <div> and </div> are not in
  the variable global

Because you defined the variable to be empty.

You quoted my suggestion of defining it to be

> <xsl:variable name="global">
>   <xsl:value-of select="/the/first/node/you/want"/>
>   <xsl:value-of select="/the/second/node/you/want"/>
>   <xsl:value-of select="/the/third/node/you/want"/>
> </xsl:variable>

but you didn't put this declaration at the top level of your stylesheet,
and you didn't change those xpaths to select whatever it is you want to
select. 

David


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread
  • xsl:variable
    • Sydney - Wed, 10 May 2000 14:37:33 +0200 (CEST)
      • <Possible follow-ups>
      • Sydney - Wed, 10 May 2000 16:01:21 +0200 (CEST)
        • David Carlisle - Wed, 10 May 2000 15:32:11 +0100 (BST) <=
      • Sydney - Wed, 10 May 2000 17:33:52 +0200 (CEST)
      • Kay Michael - Thu, 11 May 2000 09:18:11 +0100