Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 18th, 2005, 03:59 PM
Authorized User
 
Join Date: Sep 2004
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default Passing nodeset into position() function

I know this is a silly question, but I can't seem to get it.

I need to find the position of an element's ancestor element, in relation to the other elements at the ancestor's level.

Example:

<ItemSet>
    <Item>
        <Question>Question 1
    <Item>
        <Question>Question 2

If I'm currently processing the second <Question> element (Question 2), I need to know the position of its parent Item in relation to the other Item elements inside ItemSet. In this case, it should evaluate to 2.

I've tried this:

<xsl:variable name="itemPos" select="ancestor::Item[position()]" />

but my debugger shows it returning a nodeset, rather than the position.



 
Old May 18th, 2005, 04:04 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Try

count(ancestor::Item/preceding-sibling::*) + 1

You wrote:

select="ancestor::Item[position()]"

If you don't mind me saying so, that was a pretty wild guess. You're not going to get the answer to this kind of thing by trial and error.

This expression is going to return an Item, not a number; and the predicate [position()] is short for [position()=position()] which is not very useful.


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
passing references to a function demac43 Excel VBA 4 November 15th, 2006 04:23 PM
Passing an array to a Sub or Function donrafeal Access VBA 2 May 11th, 2006 09:39 AM
Passing Parameters to a function atcs2152 Ajax 4 December 22nd, 2005 09:12 AM
passing variable to function Boszky Pro PHP 2 December 15th, 2005 03:01 AM
Passing a value from one function to another PortGuy Javascript 4 October 17th, 2005 06:01 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.