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

Re: curious behavior of select= and predicates

Subject: Re: curious behavior of select= and predicates
From: "Robert P. J. Day" <rpjday@xxxxxxxxxxxxxx>
Date: Thu, 20 Mar 2003 11:21:14 -0500 (EST)
robert selec
On Thu, 20 Mar 2003, Jeni Tennison wrote:

> Hi Robert,
> 
> > First oddity -- i had always understood that "self::node()" could be
> > abbreviated as just ".". but if i replace the select expression with
> > ".[displacement]", i get the error
> 
> A predicate is only allowed in a Step, not with an AbbreviatedStep.
> "." is not textually replaced by "self::node()".

ah, sure enough, once i looked up "AbbreviatedStep" in Kay, i find,
"Note that neither . nor .. can be followed by a predicate:".
argh.  so many details, so little time.
 
> > I want the "car" template to return its string value only if it's
> > the third in context position. (again, a weird thing to do but humor
> > me.) shouldn't i be able to write:
> >
> > <xsl:template match="car">
> >  <xsl:value-of select="self::node()[position() = 3]"/>  # just pos 3
> > </xsl:template>
> 
> No. Within the predicate, the position() function returns the position
> of the context node (the node that you're testing with the predicate)
> amongst the nodes that you've selected in the step. You've only
> selected one node with the step, the <car> element itself. The
> position of the <car> element that you're testing with the predicate
> is always 1 because you only select one of them.

and once i think about it, that makes perfect sense, too.
 
> To test the position of the <car> element amongst the <car> elements
> that are having templates applied to them, use the position() function
> outside the predicate, where the current node list is made up of those
> <car> elements. Use:
> 
> <xsl:template match="car">
>   <xsl:if test="position() = 3">
>     <xsl:value-of select="." />
>   </xsl:if>
> </xsl:template>

i'd actually verified that the above worked before trying
to work the position into the predicate.

how the heck do you people remember all this stuff?

rday


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.