This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Variables in select attributes
Willy,
>I'm trying to do something like this:
[snip]
> <xsl:variable name="curr_name">
> <xsl:value-of select="name()"/>
> </xsl:variable>
> <xsl:value-of select="count(//$curr_name)"/>
> <xsl:value-of select="$curr_name"/>
There is probably a technical explanation waiting to leap forward, but you
can think of this as not working because the $curr_name variable holds a
string, something like 'foo'. If you imagine substituting that string into
the XPath expressions, you get:
<xsl:value-of select="count(//'foo')" />
<xsl:value-of select="'foo'" />
Perhaps that makes it clearer why it won't work: the XPath processor isn't
expecting a string there. You could instead try:
<xsl:value-of select="count(//*[name() = $curr_name])" />
<xsl:value-of select="*[name() = $curr_name]" />
This will give the effect that you're after in this example. There are
other alternatives, I believe, in the form of extension functions that
evaluate strings as XPath expressions, but I don't know the details of
them, nor what XSL processor you're using and whether it has them.
I hope that helps anyway,
Jeni
Dr Jeni Tennison
Epistemics Ltd * Strelley Hall * Nottingham * NG8 6PE
tel: 0115 906 1301 * fax: 0115 906 1304 * email: jeni.tennison@epistemics.co.uk
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list