[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Extract First node

Subject: RE: Extract First node
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Fri, 02 Sep 2005 16:53:00 -0400
RE:  Extract First node
I think what the OP wanted was

<xsl:template match="/a">
  <xsl:value-of select="(b/c[@type='pdf'])[1]" />
</xsl:template>

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

b/c[@type='pdf'][1]

which is short for child::b/child::c[attribute::type='pdf'][1]

and

(b/c[@type='pdf'])[1]

which is short for (child::b/child::c[attribute::type='pdf'])[1]

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:
Prakash>>
 <xsl:value-of select="b[c[@type='pdf']][1]/c/text()"/>

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


child::b[child::c[attribute::type='pdf']]

and basically just filters the b children here to those that have such a c child.

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.

Cheers,
Wendell


====================================================================== 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 ======================================================================

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.