RE: [xsl] Extract First node
Subject: RE: [xsl] Extract First node|
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Fri, 02 Sep 2005 16:53:00 -0400
I think what the OP wanted was
<xsl:value-of select="(b/c[@type='pdf'])" />
as David B. suggested.
I believe the difference between 1.0 and 2.0 value-of is a red herring
here, as the XPath was simply not correct.
The difference is between
which is short for child::b/child::c[attribute::type='pdf']
which is short for (child::b/child::c[attribute::type='pdf'])
The first expression selects all such c grandchildren that are the first
such children of their b parents (there were several in the sample given);
the second selects only the first such c grandchildren of the entire set of
such c grandchildren.
At 02:14 PM 9/2/2005, Mike wrote:
Can you explain how b[c[@type='pdf']]work? I'm not familiar with that.
Is it v2.0 syntax?
It's perfectly fine 1.0 syntax, just not useful here. It's short for
and basically just filters the b children here to those that have such a c
The logic of predicates (the [ ] syntax) is simple: test the expression
given for each node in the node set to which it applies; cast the result,
if necessary, to a Boolean value (this happens implicitly). Keep any node
for which the expression is true; toss any for which it is false.
Inside a predicate, "child::c" tests true for context nodes that have a c
element child; "c[@type='pdf']" tests true for context nodes that have a c
element child that have a type attribute = 'pdf', etc.
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