[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Unexpected ('a', 'b')[fn:position()] result
Rachel D. Basse wrote:
<xsl:template match="/"> <xsl:sequence select="('a', 'b')[fn:position()]"/> </xsl:template> Hi Rachel, It's a classic, and every now and then, I do it wrongly still (check the archives, I have once or twice asked about the same question). The function position() (you don't need to put "fn:" in front of it) returns the position of the context node. The context changes within the XPath expression to each node it is evaluating. Thus, the expression ('a', 'b')[position()] a) will test the first item in the sequence 'a' for the predicate [position()] which evaluates to the predicate [1], which is short for [position() = 1], which will return true because the current position is 1. b) will test the second item in the sequence 'b' for the predicate [position()] which evaluates to the predicate [2], which is short for [position() = 2], which will return true because the current position is 2 (we are at the second item, 'b', remember). As it comes, the following: some-node[position()] will always evaluate to true, and (some-sequence)[position()] will always return the whole sequence, because each separate item will always have the position in the sequence that equals the result of the predicate [position()]. What you want is the following: <xsl:variable name="pos" select="position()" /> <xsl:sequence select="('a', 'b')[$pos]" /> HTH, Cheers, -- Abel Braaksma http://www.nuntia.nl
|
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
|