RE: [xsl] xslt 2. index-of, nodes

Subject: RE: [xsl] xslt 2. index-of, nodes
From: David.Pawson@xxxxxxxxxxx
Date: Thu, 3 Jul 2003 13:46:02 +0100
>  Of course you can
> write your own function to get the indexes of a node in a sequence of
> nodes:
> <xsl:function name="my:index-of" as="xs:integer*">
>   <xsl:param name="seq" as="node()*" />
>   <xsl:param name="item" as="node()" />
>   <xsl:for-each select="$seq">
>     <xsl:if test=". is $item">
>       <xsl:sequence select="position()" />
>     </xsl:if>
>   </xsl:for-each>
> </xsl:function>
> or use a for expression in an XPath:
>   for $i in (1 to count($seq))
>   return if ($seq[$i] is $item) then $i else ()

Two very nice ones, thanks Jeni!

> > There are lots of loc elements with identical attribute values,
> > only the text content of the element changing. 
> >
> >  O date1
> >    date2
> >    date3
> > is the sort of svg I want.
> >
> > I'd still want the 'position' in the group, to calculate the Y
> > offset for the text, so its not an improvement...
> Erm... my point was that if you were processing the group as a whole
> then you could use the position() function to get you the position of
> the <loc> within the group. Something like:
>   <xsl:for-each-group select="loc" group-by="@hl">
>     <xsl:for-each-group select="current-group()" group-by="@side">
>       <xsl:for-each-group select="current-group()" group-by="@pos">
  That's clearer. I've just been fighting group-by="concat...
  which fails :-)
  I guessed it was possible.
  Rather long winded?
    Surprised the same ideas as the use attribute for keys isn't available.

>         <xsl:for-each select="current-group()">
>           position in group: <xsl:value-of select="position()" />
>         </xsl:for-each>
>       </xsl:for-each-group>
>     </xsl:for-each-group>
>   </xsl:for-each-group>
> (I can't believe that no one apart from me is bothered about having to
> nest <xsl:for-each-group> as in the above when you want to group by
> several things at once.)

Is this a starter for ten for Jeni's own equivalent of Muenchian techniques?

Thanks Jeni.
regards DaveP


NOTICE: The information contained in this email and any attachments is 
confidential and may be legally privileged. If you are not the 
intended recipient you are hereby notified that you must not use, 
disclose, distribute, copy, print or rely on this email's content. If 
you are not the intended recipient, please notify the sender 
immediately and then delete the email and any attachments from your 

RNIB has made strenuous efforts to ensure that emails and any 
attachments generated by its staff are free from viruses. However, it 
cannot accept any responsibility for any viruses which are 
transmitted. We therefore recommend you scan all attachments.

Please note that the statements and views expressed in this email 
and any attachments are those of the author and do not necessarily 
represent those of RNIB.

RNIB Registered Charity Number: 226227


 XSL-List info and archive:

Current Thread