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 21:40:31 GMT
True, I hadn't thought of that.  I take it then that you want to evaluate
all nodes of a certain type at position()=1, as opposed to evaluating the
first node of @type=$sometype?  Off the top of my head, I'd say you'd have
to call a named template selecting all the nodes, and then evaluate the
first node from that set, like in the 2nd example I had.  I can't think of
an expression that would do it all at once.  I'm no expert though, maybe the
XSL-list (http://www.mulberrytech.com/xsl/xsl-list) people would have a
ready answer.

> -----Original Message-----
> From: Matthew Smith [mailto:msmith@windebt.com]
> Sent: Friday, September 22, 2000 2:57 PM
> To: cocoon-users@xml.apache.org
> Subject: RE: selecting the first matching element and no more
> 
> 
> Wouldn't <xsl:apply-templates select="//language[@type=$thetype and
> position() = 1]" /> select multiple nodes if you had:
> <someparent>
>    <language type="oo">c++</language>
> </someparent>
> <someparent>
>    <language type="oo">java</language>
> </someparent>
> 	Those both have position 1 and the type oo.  I'm trying 
> to select only one
> element, no matter how many match in the entire document.
> 
> Thanks,
> Matt
> 
> -----Original Message-----
> From: Weakliem, Gordon [mailto:Gordon.Weakliem@Den.Galileo.com]
> Sent: Friday, September 22, 2000 3:20 PM
> To: cocoon-users@xml.apache.org
> Subject: RE: selecting the first matching element and no more
> 
> 
> 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
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: cocoon-users-help@xml.apache.org
> 
> 
> 
> ---------------------------------------------------------------------
> 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