cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Weakliem, Gordon" <Gordon.Weakl...@Den.Galileo.com>
Subject RE: selecting the first matching element and no more
Date Fri, 22 Sep 2000 20:20:03 GMT
Looks like you're trying to do <xsl:apply-templates
select="//language[@type=$thetype and position() = 1]" />. This selects all
the elements with matching type that have position 1 at their level in the
doc.  In your example, for type="oo", that would be c++, for "scripting"
it's "php".  If you want to select a set, then evaluate the first one in
that set (i.e. "scripting" - "javascript"), that's different problem; I
think you'd have to use 2 steps:

	<xsl:call-template name="foo">
		<xsl:with-param name="x"
select="//language[@type='$thetype']" />
	</xsl:call-template>

	<xsl:template name="foo">
		<xsl:param name="x" />
		<xsl:apply-templates select="$x[position()=1]" />
	</xsl:template>

Maybe there's a simpler way, my XPath's not the greatest.

> -----Original Message-----
> From: Matthew Smith [mailto:msmith@windebt.com]
> Sent: Friday, September 22, 2000 1:30 PM
> To: Cocoon List (E-mail)
> Subject: xsl:selecting the first matching element and no more
> 
> 
> 	Let's say I've got the following xml:
> <language type="oo">c++</language>
> <language type="scripting">javascript</language>
> <someparent>
>    <language type="scripting">php</language>
>    <language type="oo">java</language>
>    <language type="markup">html</language>
> </someparent>
> <language type="scripting">perl</language>
> 	And I want to apply templates to a language who's type 
> equals some
> variable, like this:
> <xsl:apply-templates select="//language[@type=$thetype]" />
> 	But I only want to process one.. the first one in 
> document.  I thought I
> could select that with:
> <xsl:apply-templates select="//language[@type=$thetype][1]" />
> 	But this isn't working.  How could I accomplish this?
> 
> Thanks,
> Matt
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: cocoon-users-help@xml.apache.org
> 

Mime
View raw message