This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
passing XSL variables
- To: XSL-List at lists dot mulberrytech dot com
- Subject: [xsl] passing XSL variables
- From: Jenny Simpson <simpson at cs dot utah dot edu>
- Date: Tue, 10 Jul 2001 18:32:29 -0600
- Reply-To: xsl-list at lists dot mulberrytech dot com
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