Re: [xsl] one node from multiple docs

Subject: Re: [xsl] one node from multiple docs
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Wed, 6 Feb 2002 15:19:55 +0000
Hi Matt,

> The problem: I have no trouble finding ALL of the nodes corresponding to this
> person in all of the documents... I'm just not sure how to refer to only one of
> them in the resulting node set.  If I do something like:
>
> <xsl:variable name="person"
> select="document($rtopics/descendant::rtopic/@url)/*/PARTICIPANTS/PERSON[NAME/LAST=$next-name]"
> />
>
> I think this gives me a node set containing all of the PERSON nodes
> with the desired last name (assume unique last names for the
> moment...)
>
> I'd like to now say something like:
>
> <DL><DT><xsl:apply-templates select="$person[0]" /></DT> 

In XSLT, we start counting from 1, so the first PERSON element in the
$person variable is $person[1], not $person[0]. Doing $person[0]
always gives you an empty node set. I suspect that if you do:

  <xsl:apply-templates select="$person[1]" />

then you'll get what you want (although it's not guaranteed which
document this PERSON element will come from).

> or
>
> <DL><DT><xsl:apply-templates select="$person[last()=1]" /></DT> 

The last() function returns the number of the last node in the list
you're processing. If you have three PERSON elements held in the
$person variable, then last() will return 3. So doing what you do
above actually gives you the single PERSON in the $person node set *if
and only if* there is only one PERSON in the $person node set. If your
path above returns more than one PERSON element, then you don't select
any node.

If you wanted to get the last PERSON rather than the first PERSON,
then you could use:

  <xsl:apply-templates select="$person[last()]" />

If you prefer, you can expand either of these options (for getting the
first or last of the node set) to their full form to get exactly the
same effect:

  $person[position() = 1]
  $person[position() = last()]

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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


Current Thread