RE: Extract First node
<xsl:template match="/a"> <xsl:value-of select="(b/c[@type='pdf'])" /> </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
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:
Prakash>> <xsl:value-of select="b[c[@type='pdf']]/c/text()"/>
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 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.
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