|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: how to test if a child node have a specific name?
At 2004-05-28 21:30 +0800, Chen Yi wrote:
Thanks for you advise. But I still have a question. I think the following expresstion is correct.<xsl:if test="name(child::node()[1])='NodeName'"> ... </xsl:if> There are four different types of nodes found along the child:: axis - elements, comments, processing instructions, and text nodes. When you use "node()" you are checking *all* four kinds of node along the given axis. When you use "*" you are checking only elements along the given axis. And, yes, it happens to be true that your expression works regarding the node name, but I did qualify my suggestion by saying that it works in this limited situation where your element types are not namespace-qualified ... you asked for the "correct" expression, and I maintain that the "correct" expression is to use the self:: axis and not to use the name() function. When I teach XSLT I underscore that the name() function is suitable for exposition but not suitable for node checking. I maintain that your expression above is not sufficient in the general case because of possible text nodes at the start of your child nodes and of possible future use of namespace-qualified element types, therefore I will stick to: test="child::*[1][self::NodeName]" as being the "correct" way to do what you have requested. I hope this helps. ......................... Ken
World-wide on-site corporate, govt. & user group XML/XSL training. 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) Male Breast Cancer Awareness http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
|
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
|

Cart








