Re: [xsl] using variables correctly

Subject: Re: [xsl] using variables correctly
From: "Joe Fawcett" <joefawcett@xxxxxxxxxxx>
Date: Mon, 02 Jun 2003 15:17:50 +0100
From: "Krueger, Philipp" <Philipp.Krueger@xxxxxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx, xsl-list-digest@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] using variables correctly
Date: Mon, 2 Jun 2003 15:41:13 +0200

i try to write a dynamical database using xsl-processing and somehow i can't
get the variables to work correctly:


<xsl:if test="$search != ''">
<xsl:for-each select="database/computer[@owner = $searchparam]">

the if works, the for works as well, but only if i use "@owner" - if i write
the following line "<xsl:for-each select="database/computer[$search =
$searchparam]">" ($search is "@owner") the output stays empty... now i
wonder: why does comparing to a variable work with "xsl:if" but not with
"xsl:for-each"? i also tried setting the whole content of the
"select"-statement as a variable but that neither worked ($search was
"database/computer[@owner = $searchparam]"). i also tried to set $search to
$search = "$searchparam" and use that as in "<xsl:for-each
select="database/computer[$search]">"but that neither worked. i am desperate
- can anybody help, please?


greetings,

philipp

You could change the for-each to:
<xsl:for-each select="database/computer[@*[name() = $search] = $searchparam]">


but then $search would have to contain 'owner' rather than '@owner'. If you are using namespaces on the attributes you can change name() to local-name().

Joe

_________________________________________________________________
Sign-up for a FREE BT Broadband connection today! http://www.msn.co.uk/specials/btbroadband



XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread