Subject: Re: [xsl] accessing last element of node set passed as parameter From: David Carlisle <davidc@xxxxxxxxx> Date: Tue, 21 May 2002 18:09:50 +0100 |
produce identical output given the input: <IN><A/><A/><A/><A/><A/><A/></IN> Below is a transform in which the two lines: <xsl:copy-of select="($result/BAR)[last()]" /> <xsl:copy-of select="$result[last()]" /> "$result|xalan:nodeset($new)"/> Ha! I guessed two possible meanings: > But they can not have done. If $result holds a root node then > $result/BAR > selects all the BAR children of that node and > ($result/BAR)[last()] > selects the last of those children. > > But if $result contains three BAR nodes then > > $result/BAR > > selects all the BAR children of each element of $result, and that is > empty so ($result/BAR)[last()] is similarly empty. > > But in fact you have a third. $result in this case contains three _root_ nodes so $result does have three nodes, so <xsl:copy-of select="($result/BAR)[last()]" does pick out the last. But they are root nodes not BAR nodes so "($result/BAR)[last()]" gives you the last BAR. Since copy-of throws away root nodes and just gives you thier contents, you do get the same. Note however that it is undefined which one you get, you are taking the union of a new root node with a set of existing root nodes. Root nodes are in an implementation defined order so you can not be sure that the last one you added is the one you get with last(). If the order matters you need to make sure your bar elements are siblings of each other, then the result variable will have a single root node containing the elements that you are interested in. David _____________________________________________________________________ This message has been checked for all known viruses by Star Internet delivered through the MessageLabs Virus Scanning Service. For further information visit http://www.star.net.uk/stats.asp or alternatively call Star Internet for details on the Virus Scanning Service. XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] accessing last element of, paul morgan | Thread | Re: [xsl] accessing last element of, paul morgan |
Re: [xsl] accessing last element of, paul morgan | Date | Re: [xsl] one key or a whole bunch?, Jeni Tennison |
Month |