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 August 5th, 2005, 03:11 AM
Authorized User
 
Join Date: Aug 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Selecting attributs

Hi,
I am trying to select the value of the last attribute in a set of nodes.
The node set is something like:
    <list>
      <item key="1">
        <tname>1,1</tname>
          </item>
      <item key="2">
        <tname>2,3</tname>
      </item>
     </list>

and the syntax used to get the last attribute is:
<xsl:value-of select="/parameters/parameter[name=$parameter]/list/item[last()][@key]"/>

but this only gives me the text value of the node item (2,3) not the value of the key (2). Why is this?

 
Old August 5th, 2005, 04:15 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Think of "/" as meaning "then get...", and "[]" as meaning "selecting only those that have ...". So something that ends /list/item[last()][@key] means "then get the child list elements, then get the child item elements, selecting those that are the last item, selecting only those that have a key attribute".

If the thing you want to select is a key attribute, then the final "/" will be followed by "@key".

Note also that a/b[last()] selects every b that is the last child of its parent a. If you want the last b among all the a's, use (a/b)[last()].

So you probably want (list/item)[last()]/@key, or possibly (list/item/@key)[last()] - if every item has a key these are equivalent.



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old August 5th, 2005, 04:21 AM
Authorized User
 
Join Date: Aug 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What a usefull answer. I finally understand.

Thankyou.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Selecting MAX Value nirmal_s19 SQL Server ASP 1 May 8th, 2007 01:04 AM
help in selecting elements spandit XSLT 1 April 9th, 2007 07:27 PM
Selecting elements up until a certain one Frode XSLT 5 January 19th, 2006 01:22 PM
Selecting Data.. NitinJoshi General .NET 3 January 18th, 2005 02:59 AM
Selecting once where there are many onlyu2 MySQL 1 March 25th, 2004 06:22 AM





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