This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Scope of a variable
- To: xsl-list at mulberrytech dot com
- Subject: Scope of a variable
- From: prasadm at crt dot com
- Date: Fri, 17 Mar 2000 09:09:04 -0600
- Reply-To: xsl-list at mulberrytech dot com
> Hi guys,
>
> I am writing a stylesheet to generate an HTML output. A variable value is
> set
> in the parent template and I am trying to access the same in the child
> templates as shown below.
>
> <MAINTAG num="2">
> <FIRST>
> <COL1> abc </COL1>
> <COL2> 123 </COL2>
> <FIRST>
> <SECOND>
> ...
> </SECOND>
> </MAINTAG>
>
> In the style sheet I put the attribute "num" value into a variable in
> MAINTAG template
> and want to access the same in the template for FIRST.
> written for "FIRST" or "SECOND", etc.
>
> <xsl:template match="MAINTAG">
> <xsl:variable name="num">
> <xsl:value-of select="@num"/>
> </xsl:variable>
> <xsl:apply-template select="FIRST">
> <xsl:apply-template select="SECOND">
> </xsl:template>
>
> <xsl:template match="FIRST">
> <INPUT TYPE="HIDDEN" NAME="hidNum">
> <xsl:attribute name="VALUE">
> <xsl:value-of select="$num"/>
> </xsl:attribute>
> <xsl:apply-templates/>
> <xsl:template>
>
>
> When I use the parser to parse this, it gives an error saying unknown
> variable.
> How is the scope of a variable defined.
> Is this possible to do or not? If not, is there any work around.
>
> Thanks,
> Prasad
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list