Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 20th, 2005, 09:38 AM
martin.tschofen@gmail.com
Guest
 
Posts: n/a
Default select only the first node from a for-each loop that contains a specific element

How do I select only the first node from a for-each loop that contains
a the element "photo".

the following xsl finds all "art" elements that have a "photo" element.
The problem is that I only want to output the first found result. The
way I've written the xsl I get a couple "photo" elements.
Here's my xsl:

<xsl:template match="/topixfeed">
<!--some additional stuff happens here that finds the parent of all
"art" elements-->
<xsl:for-each select="art">
<xsl:choose>
<xsl:when test='photo'>
<h3><xsl:number/><xsl:value-of select="title"/></h3>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</div>
</xsl:template>

Thanks for any help...mt

  #2  
Old July 20th, 2005, 09:39 AM
Volkm@r
Guest
 
Posts: n/a
Default Re: select only the first node from a for-each loop that containsa specific element

martin.tschofen@gmail.com wrote:[color=blue]
> How do I select only the first node from a for-each loop that contains
> a the element "photo".
>
> the following xsl finds all "art" elements that have a "photo" element.
> The problem is that I only want to output the first found result. The
> way I've written the xsl I get a couple "photo" elements.
> Here's my xsl:
>
> <xsl:template match="/topixfeed">
> <!--some additional stuff happens here that finds the parent of all
> "art" elements-->
> <xsl:for-each select="art">
> <xsl:choose>
> <xsl:when test='photo'>
> <h3><xsl:number/><xsl:value-of select="title"/></h3>
> </xsl:when>
> </xsl:choose>
> </xsl:for-each>
> </div>
> </xsl:template>
>
> Thanks for any help...mt
>[/color]
<http://zvon.org/xxl/XPathTutorial/Output/example4.html#b9b1c33c23>

So you might try

<xsl:template match="/topixfeed/art/photo[1]">
<h3><xsl:number/><xsl:value-of select="title"/></h3>
</xsl:template>
<xsl:template match="/topixfeed/art/photo">
<!--Your action for all the others but the first onee -->
</xsl:template>

HTH
--
Volkm@r
  #3  
Old July 20th, 2005, 09:39 AM
Dimitre Novatchev
Guest
 
Posts: n/a
Default Re: select only the first node from a for-each loop that contains a specific element


<martin.tschofen@gmail.com> wrote in message
news:1116387456.198555.8000@g49g2000cwa.googlegrou ps.com...[color=blue]
> How do I select only the first node from a for-each loop that contains
> a the element "photo".
>
> the following xsl finds all "art" elements that have a "photo" element.
> The problem is that I only want to output the first found result. The[/color]

This is an artificially created problem. If only the first element in the
node-set must be processed, then instead of:

<xsl:for-each select="$someNode-set">
<!-- Whatever processing is necessary here -->
</xsl:for-each>

Use:
<xsl:for-each select="($someNode-set")[1]>
<!-- Whatever processing is necessary here -->
</xsl:for-each>


Cheers,
Dimitre Novatchev
[color=blue]
> way I've written the xsl I get a couple "photo" elements.
> Here's my xsl:
>
> <xsl:template match="/topixfeed">
> <!--some additional stuff happens here that finds the parent of all
> "art" elements-->
> <xsl:for-each select="art">
> <xsl:choose>
> <xsl:when test='photo'>
> <h3><xsl:number/><xsl:value-of select="title"/></h3>
> </xsl:when>
> </xsl:choose>
> </xsl:for-each>
> </div>
> </xsl:template>
>
> Thanks for any help...mt
>[/color]


 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles