This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: How can I use a variable out of it scope ?



> The following code puts on "my_var" the totality of the Name attributes of 
> each element "Level_1" :

Yes, slightly strangely, just concatenates them all together as a text
node, which is a very unusual thing to want to do.


> Now myvar contains "Name_1Name_2...Name_n..." as a string.
> And I want to use it on the Level_2 match:


If you really want to do that, you don't want a variable at all, you
want a parameter:


      <xsl:apply-templates>
	<xsl:with-param name="my_var">
		<xsl:for-each select="Level_2">
			<xsl:value-of select="./@Name"/>
		 </xsl:for-each>
	</xsl:with-param>
      </xsl:apply-templates>

</xsl:template>



<xsl:template match="Level_2">
 <xsl:param name="my_var"/>
  .... $my_var...


However, you don't _need_ to use any kind of variable or parameter at
all if you don't want to. The entire source tree is available to every
template, so the information is there anyway, whether or not you copy it
into a vraiable.

You could just as well have gone

<xsl:template match="Level_2">
          <xsl:for-each select="../Level_2">
			<xsl:value-of select="./@Name"/>
          </xsl:for-each>


David

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]