[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: "Passin, Tom" <tpassin@xxxxxxxxxxxx>
Date: Thu, 20 Mar 2003 11:50:17 -0500
tom selec
[Robert P. J. Day]
 
>   [more pedantics involving simple examples.  the following results
> are from "xsltproc", so it may be a processor-related thing.]
> 
> 
>   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
> 

Predicates are not allowed for the "." and ".." shorthand syntax.  Why?
Unclear, but it is in the XPATH Rec.

> 
>   should i not expect "self::node()[displacement]" to be logistically
> equivalent to ".[displacement]"?  or did i misread something?
>   

You would but it is specifically disallowed.

> Second puzzler
> --------------
> 
>   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>
> 
>   instead, i get nothing, even though i've verified that the 
> consecutive
> invocations of the "car" template do, in fact, run through the context
> positions 1 -> 4 for each "car" element.
> 

You are asking for the context node - which is the only node on the self
axis -, to return all  its nodes and then of those, then return the
string value of the third.  The self axis will only return the context
node, so position() = 3 will never return anything (only position() = 1
will).  You can check this out by writing 

=<xsl:copy-of select="self::node()"/>=

and see what you get.

If you want to see data of the just the third car, you could write 

<xsl:if test='position()=3'><xsl:value-of select='model'/></xsl:if>



Cheers,

Tom P

 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.