Subject: RE: [xsl] passing XSL variables From: "Robert C. Lyons" <boblyons@xxxxxxxxxx> Date: Tue, 10 Jul 2001 23:35:56 -0400 |
Jenny, The following should work: <xsl:choose> <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 http://www.dpawson.co.uk/xsl/sect2/nono.html: "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. Bob <sig name = 'Bob Lyons' title = 'XML Consultant' company = 'Unidex, Inc.' phone = '+1-732-975-9877' email = 'boblyons@xxxxxxxxxx' url = 'http://www.unidex.com/' 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"> <author> <firstname>P.</firstname> <middlename>V.</middlename> <middlename>C.</middlename> <lastname>Hough</lastname> </author> <title>Method and Means of Recognizing Complex Patterns</title> <year>1962</year> <note>U.S. Patent 3,069,654</note> </bibitem> I want to use the following bit of code to search the xml document for nodes whose year matches a variable $search. <xsl:choose> <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:choose> <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: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] passing XSL variables, Jenny Simpson | Thread | RE: [xsl] passing XSL variables, Michael Kay |
Re: [xsl] [XSL] How can I seek info, Robert Koberg | Date | [xsl] Re: passing XSL variables, Dimitre Novatchev |
Month |