Subject: Re: [xsl] xsl:include From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx> Date: Tue, 27 Mar 2001 09:49:39 +0100 |
Hi, > One simple thing seems not to work. I want to include some variables > from an extra stylesheet into another stylesheet. There are a few things wrong with: > <?xml version="1.0"?> > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> > <xsl:import href="variable.xsl"/> > > <xsl:value-of select="var1"/> > <xsl:value-of select="var2"/> > > </xsl:stylesheet> First, those xsl:value-of instructions need to be within a template to get them to be recognised: <xsl:template match="/"> <xsl:value-of select="var1" /> <xsl:value-of select="var2" /> </xsl:template> Second, here you're getting the var1 and var2 *child nodes* of the current node within the template (i.e. the root node). References to variable values have the syntax: '$' + variable-name So you want something like: <xsl:template match="/"> <xsl:value-of select="$var1" /> <xsl:value-of select="$var2" /> </xsl:template> to get the values of the variables called 'var1' and 'var2'. Third, the variables that you're setting in variable.xsl are actually called 'var' and 'var1', so you will get an error if you try to access the value of the variable 'var2' as it doesn't exist. I think you want: <xsl:template match="/"> <xsl:value-of select="$var" /> <xsl:value-of select="$var1" /> </xsl:template> or of course you could change the names of the variables in variable.xsl. By the way, you'll probably be better off setting the variables using the select attribute rather than their content, if you can do so: <xsl:variable name="var" select="'Something'" /> <xsl:variable name="var1" select="'Something'" /> I hope that helps, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] xsl:include, Partho Paul | Thread | Re: [xsl] xsl:include, David Carlisle |
RE: [xsl] Can one element have more, DPawson | Date | RE: [xsl] How to preserver white sp, Michael Kay |
Month |