[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] curious behavior of select= and predicates


Subject: RE: [xsl] curious behavior of select= and predicates
From: "Passin, Tom" <tpassin@xxxxxxxxxxxx>
Date: Thu, 20 Mar 2003 11:50:17 -0500

[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
Keywords