473,322 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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

Jul 20 '05 #1
2 1712
ma*************@gmail.com wrote:
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

<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
Jul 20 '05 #2

<ma*************@gmail.com> wrote in message
news:11********************@g49g2000cwa.googlegrou ps.com...
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
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
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

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: CB | last post by:
I know I can select a node by attribute value using something like <xsl:apply-templates select="//*"/> How can I replace Joe with an attribute from the current node? I.e., the current node...
6
by: Paul J Lay | last post by:
I am using the XmlDocument Select Nodes method and it seems to work OK except that it returns embedded nodes in the collection when I only want the nodes that are not embedded. For example I have...
8
by: K.Fawcett | last post by:
I am doing a simple insert into a table and I would like the data to be retrieved in the order it is inserted not by what appears to be alphabetical order. insert into mytbl values('c') insert...
2
by: paradox | last post by:
How can I go about having a TreeNode selected when I right click? I tried using the Click event, but the event does not pass in the node that was clicked. Currently you have to left click a node...
1
by: Joerg Trumpfheller | last post by:
Hey people, how can I select a treenode with the MouseButtons.Right event if there is no contextmenu? I build up a treeview with 3 levels. Only if the second level is selected, there should...
3
by: Matthew Woods | last post by:
Hi, does anyone know how to select a treenode with the first click? the first click on a treeview will highlight the node under the mouse when it was clicked BUT that node isn't actually selected...
1
by: Vern | last post by:
I've tried the following, but keep getting the error "Object reference not set to an instance of the object." TreeNode node = tvHistory.Nodes.FirstNode; tvHistory.SelectedNode = node; I've...
3
by: EdB | last post by:
I am using the TreeView control and trying to determine if the user has selected the top node. Using the After_Select method, what I am seeing is that if I click on a lower node, the...
4
by: Matt Kruse | last post by:
According to standards, if an option is selected and it has no VALUE attribute, the contents of the option tag is to be submitted. So: <select name="sel"> <option selected>Value</option>...
9
by: Thom Little | last post by:
Using C# 3.5 I want to select a value from an XML file. The intent of the following is to print "EpsilonGamma". It does not work. Can you point out my probably very obvious error? XmlDocument...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.