Subject: Re: [xsl] curious behavior of select= and predicates From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Thu, 20 Mar 2003 16:13:56 +0000 |
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()". > 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. 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> Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] curious behavior of select= a, Robert P. J. Day | Thread | Re: [xsl] curious behavior of selec, Robert P. J. Day |
[xsl] curious behavior of select= a, Robert P. J. Day | Date | Re: [xsl] curious behavior of selec, Robert P. J. Day |
Month |