RE: [xsl] passing XSL variables

Subject: RE: [xsl] passing XSL variables
From: "Robert C. Lyons" <boblyons@xxxxxxxxxx>
Date: Tue, 10 Jul 2001 23:35:56 -0400

The following should work:

        <xsl:when test="$search">
            <xsl:for-each select="bibliography/bibitem">
		    <xsl:if test="*[name() = $field] = $search">

>From Dave Pawson's "Things XSLT can't do" at

	"In general in XSLT you can't use variables to contain
	expressions, patterns, or parts thereof, you can only
	use them to hold strings, numbers, node-sets, and booleans."

Hope this helps.


<sig name    = 'Bob Lyons'
     title   = 'XML Consultant'
     company = 'Unidex, Inc.'
     phone   = '+1-732-975-9877'
     email   = 'boblyons@xxxxxxxxxx'
     url     = ''
     product = 'XML Convert: transforms flat files to XML and vice versa' />

-----Original Message-----

This question has probably been answered several times, but I was unable
to find it in the archives so I'll risk repetition.  I want to pass a
variable as the name of an xml child element but the variable isn't
being interpreted the way I need it to be.  For example,
here is the XML node:
    <bibitem type="unpublished" label="Hough62">
        <title>Method and Means of Recognizing Complex Patterns</title>
        <note>U.S. Patent 3,069,654</note>

I want to use the following bit of code to search the xml document for
nodes whose year matches a variable $search.

	<xsl:when test="$search">
		<xsl:for-each select="bibliography/bibitem">
		<xsl:if test="($search=year)">

However, instead of using the literal string 'year', I want to use a
variable containing the string 'year'.  However, if I substitute the
variable $field (which contains 'year') for 'year', as follows, the
comparison doesn't work.

	<xsl:when test="$search">
		<xsl:for-each select="bibliography/bibitem">
		<xsl:if test="($search=$field)">

I've tried using single quotes, parentheses, and even the substring
function to get the variable to be interpreted as it should be, but to no
avail.  I'd be interested in any tips on using xsl variables in
general.  Thanks in advance.

Jenny Simpson
Sci Institute

 XSL-List info and archive:

Current Thread