Re: [xsl] OR statement

Subject: Re: [xsl] OR statement
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 03 Jun 2003 11:42:43 -0400
At 2003-06-03 09:02 -0600, Alan Gardner wrote:
I've tried a couple of approaches:
<xsl:if test="(name() = pubdate or dc:date)">

The above or statement is broken down into operands as follows:


name() = pubdate

which checks to see if the name of the current node is equal to the text of the pubdate child of the current node (which you don't want) and

dc:date

which is testing for any dc:date children (which you don't want).

You probably wanted to quote the names and re-use the name() function, but that is not the safest way to do the test you want.

If you want to check "am I a pubdate element or am I a dc:date element" for the current node, then the safest test you want is:

test="self::pubdate or self::dc:date"

or

test="self::pubdate | self::dc:date"

where "|" is "union" not "or".

The only safe use of the name() function is to get the name of the current element for display purposes ... because using it for node checking is not namespace-safe.

I hope this helps.

...................... Ken

--
Upcoming hands-on courses: (registration still open!)
-      (XSLT/XPath and/or XSL-FO) North America: June 16-20, 2003

G. Ken Holman                mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.         http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0   +1(613)489-0999 (F:-0995)
ISBN 0-13-065196-6                      Definitive XSLT and XPath
ISBN 0-13-140374-5                              Definitive XSL-FO
ISBN 1-894049-08-X  Practical Transformation Using XSLT and XPath
ISBN 1-894049-11-X              Practical Formatting Using XSL-FO
Member of the XML Guild of Practitioners:    http://XMLGuild.info
Male Breast Cancer Awareness http://www.CraneSoftwrights.com/s/bc


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



Current Thread