[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: use variable in <xsl:if test=
Sorry for only explaining the half of my problem. Instead of writing <xsl:if test="*//author='C. J. Date']"/> 10 times in my stylesheet I want to use ONE variable or constant to set it once at the beginning and then use it like that: <xsl:if test=variable/> How must I declare this variable and how do I use it in xsl:if??????????? ----- Original Message ----- From: "Matt Gushee" <mgushee@xxxxxxxxxxxxx> To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> Sent: Saturday, March 02, 2002 12:33 AM Subject: Re: use variable in <xsl:if test= On Sat, Mar 02, 2002 at 12:21:29AM +0100, Robert Sösemann wrote: > How in the world ;-) can i use a variable in <xsl:if test=..> > > <xsl:variable name="condition" select="*[.//author='C. J. Date']"/> > > <xsl:template match="node()[name()=$entity]"> > <xsl:if test="boolean(string($condition))"> There is nothing syntactically wrong with this. It would help if you explained what result you are expecting. > This does not work neigther with > {$condition} It shouldn't. You can't use attribute value templates in <xsl:if test="">. You just put the variable reference in the attribute value, as in your example. And it's okay to use the variable as an argument to a function, and to nest functions. Maybe you just have the wrong idea about what your XPath expression is doing. In particular, I can't see a reason why you would need to use both boolean() and string(). If $condition is an empty node-set, then both boolean($condition) and string($condition) should evaluate to false. Ah, wait. I think I see the problem. It looks like you are defining the variable at the top level of the stylesheet, aren't you? In that case, it's always going to be false. '*' means 'any child _element_ of the current context node'. At the top level of the stylesheet, there are no child elements. You should probably define the variable within a template, where you have more context information to work with. -- Matt Gushee Englewood, Colorado, USA mgushee@xxxxxxxxxxxxx http://www.havenrock.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list 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
|