Thanks for you advise.
But I still have a question.
I think the following expresstion is correct.
explain it to me ? Thanks.
Subject: Re: [xsl] how to test if a child node have a specific name?
Date: Fri, 28 May 2004 09:14:35 -0400
Post by Chen YiI want to test if the first child node is a specific name
"NodeName" node.I use the following expression.
<xsl:if test="child::node()[1]=NodeName">
...
</xsl:if>
But it doesn't work.
(1) the first of the child nodes might not be an element (when
people type XML they often put newline sequences at the end of start
tags creating text nodes as the first child node)
(2) your second operand is evaluated as the text content of the
first child name "NodeName", which isn't what you want.
Post by Chen YiThen I changed the expression to
<xsl:if test="child::node()[1]='NodeName'">
...
</xsl:if>
or
<xsl:if test="name(child::node()[1])='NodeName'">
...
</xsl:if>
They all seem work.
But they are not namespace-safe (even though you aren't yet using
namespaces), and it seems you are lucky that the first child node is
not a text node. And I'm surprised the first of those actually
works since you are not testing the name of the node but rather you
are testing the text content of the node.
Post by Chen YiI want to know which one is the correct one?
I suggest "none of the above" ... I would suggest the "correct"
test="child::*[1][self::NodeName]"
as this first looks at all children elements (ignoring child text
nodes), filters out only the first one, and then filters that one as
being an element with the name "NodeName". The resulting node set
is empty if the element is not as desired, and non-empty if the
element is as desired, resulting in the associated false/true
boolean test. Using this style of check will allow you to migrate
test="child::*[1][self::ns:NodeName]"
I hope this helps.
............................ Ken
--
Public courses: Spring 2004 world tour of hands-on XSL instruction
Next: 3-day XSLT/XPath; 2-day XSL-FO - Birmingham, UK June 14,2004
World-wide on-site corporate, govt. & user group XML/XSL training.
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
--+------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
--+--