Re: node indexing in a select statement

Subject: Re: node indexing in a select statement
From: David Allouche <david@xxxxxxxxxxxxxxxx>
Date: Mon, 21 Aug 2000 23:07:21 -0200 (GMT+2)
On Mon, 21 Aug 2000 Yazil_Santoyo@xxxxxxxxxx wrote:

> I'm trying to get a specific param from a specific instance of
> <Details>.  I've been trying to do it like :
> 
>                <xsl:variable name="Param"><xsl:value-of
> select="//Details($ID)/Param2"/></xsl:variable>
> 
> ( Where ID is a variable defined in the xsl code ) but it doesn't work...  it
> seems like XSL doesn't like the indexing (ie. (x) ) inside the select
> statement... 

Inside a XSLT expression, the only words that can be followed by
parenthesises are function names.  Here, Detail is an element name, so no
surprise it does not work.

It's hard to tell what is the correct formulation for what you want to do
without any further information, but here are possible solutions.

If you are looking for a Details element with a matching attribute named
attr, and that $ID is a string or a one element node-set (this is needed
because @id is a node set and comparison involving node sets follow very
special rules) you could use:

select="//Details[@attr=$ID]/Param2"

If you are looking for a Details element with a matching ID attribute
(that is an attribute of type ID in the DTD, not an attribute named ID),
and the source XML declaration includes a DOCTYPE declaration that
identify the DTD, and the document is valid (wich implies ID are unique)
and you are using a good enough parser (XSLT does not requires the parser
to identify ID attributes), you could use:

select="id($ID)/Param2"

If you are looking for the Nth Details which is child of the context
element, where $ID=N (it may be what you mean when you talk of index), you
can use:

select="//Details[position()=$ID]/Param2"

or if $ID contains a number value (which means most of the time it has
been explicitely cast using the number() function)

select="//Details[$ID]/Param2"


In all cases you need to read a good book on XSLT before doing any serious
work.  Michael Kay's (the author saxon) "XSLT Programmer's Reference" is a
very good book that can be read in nearly any order.  It will get you
started quick and can lead you to mastery of this wonderful language.



                             -- David --


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread