RE: [xsl] Are variables allowed in XPATHs?

Subject: RE: [xsl] Are variables allowed in XPATHs?
From: "Roger Glover" <glover_roger@xxxxxxxxx>
Date: Mon, 3 Feb 2003 00:19:39 -0600
Harry Ohlsen wrote:

> > It might help if you gave us a look at the exact pattern 
> > to which XMLSpy was objecting.
> Sorry, I thought the problem was pretty generic 
> and didn't want to muddy things by being too 
> specific.  Ie, is it legal to use a variable in an 

The problem is that the situation is not that simple.  In
XSLT XPath *Expressions*, it certainly is legal to have
variable values.  You can verify this with examples from the
following sections of the spec:
not to mention many, many other examples from the XSL FAQ:

However, XSLT XPath *PATTERNS* (often?) may not contain
variable values. Patterns are the more restricted XPath
syntax used in xsl:template/@match, xsl:key/@match,
xsl:number/@count, and xsl:number/@from.  See the spec here:

I say "(often?)" above since the section on patterns says
nothing about disallowing variables, and while the spec
specifically prohibits variable and parameter values in the
two "match" attributes above, it is silent about any such
restriction on the "count" and "from" attributes of

> Here's the code it's complaining about (apologies 
> for the line wrapping):
> <xsl:template name="delete-section" 
> match="/main/document/item[property[(name='report') 
> and (value=$sectionToDelete)]]">
>      </xsl:template>

So, it is very useful to see your specific case, since it
falls into this latter category of patterns that cannot use
variable values.  Xalan should have flagged this as an error.

-- Roger Glover

 XSL-List info and archive:

Current Thread