cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c..@step.de (Christian Frank)
Subject Re: selecting the first item
Date Mon, 13 Dec 1999 08:26:58 GMT
Jeremy Quinn wrote:

> Dear All,
>
> I am trying to select only the first "section" child node of a "content" node that could
contain zero - many sections.
>
> within the main selector I have the following:
>
>     <xsl:apply-templates select="content"/>
>
> which triggers:
>
>     <xsl:template match="content">
>         [...]
>         <xsl:when test="section">
>             <xsl:apply-templates match="section[1]" mode="first"/>
>         </xsl:when>
>         [...]
>     </xsl:template>
>
> ie. if there is a section, choose the first
>
>     <xsl:template match="section" mode="first">
>         [...]
>     </xsl:template>
>
> The problem is that all sections get immediately processed by this template not just
the first.
>
> I am having to resort to using an <xsl:if test="position()=1"> to seperate out
the first section. I am sure it must be possible to avoid the conditional execution.
>
> Any suggestions?

Hi Jeremy,

I suggest the following:

<xsl:template match="content/section[position()=first()]">
... do_your_procesing ...
</xsl:template>

This rule should only be applied to the first section child of a content parent.

Greetings,
Christian
--
Christian Frank
Software Services
________________________________________________________________
STEP GmbH                                      Tel.: +49 9365 8062-0
Technologiepark Rimpar                         chf@step.de
97222 Rimpar                                   http://www.step.de
________________________________________________________________



Mime
View raw message