xsl-list
[Top] [All Lists]

RE: Selecting the first item from a tokenized string

2006-01-13 07:22:50
Michael Kay wrote:

you can get the Nth item in a sequence using SEQ[N].
In the rare cases where that's inconvenient because
it changes the evaluation context, you can use
subsequence(SEQ, N, 1).

  When can this happen?  Can you show an example?

  Regards,

--drkm


Suppose that you have a structure like this:

<e>
  <itemref nr="5"/>
  <itemref nr="7"/>
  <itemref nr="10"/>
</e>
<f>
  <item/>...
</f>

and you want to select the 5th, 7th, and 10th <item> elements.

You can't do 

<xsl:for-each select="/e/itemref">
  <xsl:value-of select="/f/item[(_at_)nr]"/>

because the context inside the predicate is wrong.

But you can do

<xsl:for-each select="/e/itemref">
  <xsl:value-of select="subsequence(/f/item, @nr, 1)"/> 

Of course there are other circumventions as well, involving variables or
current() - but it's nice to be aware of this alternative.

Michael Kay
http://www.saxonica.com/

-----Original Message-----
From: Florent Georges [mailto:darkman_spam(_at_)yahoo(_dot_)fr] 
Sent: 13 January 2006 13:14
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] Selecting the first item from a tokenized string



















      

      
              
______________________________________________________________
_____________ 
Nouveau : téléphonez moins cher avec Yahoo! Messenger ! 
Découvez les tarifs exceptionnels pour appeler la France et 
l'international.
Téléchargez sur http://fr.messenger.yahoo.com

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--





--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--