Re: use variable in <xsl:if test=
Could you be more specific by what you mean by "not work"?
A variable in a test expression is evaluated just as is any other expression. The test expression requires a Boolean. XPath has quite clear rules (albeit somewhat complex) to determine how different data object types such as node sets (the type you have set your variable to, below) are cast as Booleans. (In this case, a node-set tests as true if it is not empty, i.e. if it has one or more nodes in it.)
If it's not behaving as you expect, that's either because:
1 You aren't expecting the right thing 2 There is a bug in your processor
We need to nail down #1 before we can entertain #2 (though you might reassure us by telling us what processor you're using: what bugs may be found in the commoner ones, e.g. Saxon, MSXML, Xalan, are pretty well known on this list).
If you're expecting the wrong thing, it's likely because you don't understand how variables are set, or because you don't understand how expressions are evaluated as Booleans.
So what do you mean, "it doesn't work"? Are you getting an error?
In the code below, if you are setting the variable at the top level to be available globally, and you want it to contain any element throughout that contains an author element whose value is the string "C. J. Date", then try
<xsl:variable name="condition" select="//*[.//author='C. J. Date']"/>
But this is just a guess, since you haven't told us either what you want your variable to hold, where you are declaring it (this is important since XPath works relative to a context node), and what your source looks like (so we can judge whether the XPath is constructed correctly).
As for the XSLT itself, <xsl:if test="$condition">...</xsl:if> is legal and done all the time; so if it's not working you need to tell us how you know it's not working, and how you would know if it were. The problem is probably in your XPath.
(For example -- another wild guess -- are you aware the instruction <xsl:copy-of select="*"/> means "copy all the element *children* of the context node"?)
At 06:21 PM 3/1/2002, you wrote:
How in the world ;-) can i use a variable in <xsl:if test=..>
====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format