Get all <img> Tags that are siblings?

Please support our XML, XSLT and XPATH advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2009
Posts: 1
Reputation: Psybear is an unknown quantity at this point 
Solved Threads: 0
Psybear Psybear is offline Offline
Newbie Poster

Get all <img> Tags that are siblings?

 
0
  #1
Oct 19th, 2009
Hi all

I need to detect all image tags in a HTML document that are siblings:

  1. <p>
  2. <img ../>
  3. <img ../>
  4. <img ../>
  5. </p>
  6. <p>
  7. <img ../>
  8. </p>

In the example above I need to detect the first three img tags, but not the fourth.

In contrary, I also need to detect the img tags that do NOT have direct img siblings.

Sadly I have no idea how to do this. Any hint, please? Thanks.
Josh
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 134
Reputation: hielo is on a distinguished road 
Solved Threads: 21
hielo hielo is offline Offline
Junior Poster
 
0
  #2
Oct 19th, 2009
  1. var siblings=[]
  2. for( var i=0, limit=document.images.length-1; ++i)
  3. {
  4. if( document.images[i].parentNode===document.images[i+1].parentNode)
  5. siblings[siblings.length]=i;
  6. }
  7. alert( siblings.join("\n") );
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 134
Reputation: hielo is on a distinguished road 
Solved Threads: 21
hielo hielo is offline Offline
Junior Poster
 
0
  #3
Oct 19th, 2009
sorry, the for clause should be
  1.  
  2. for( var i=0, limit=document.images.length-1; i < limit; ++i)
  3. ...
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 2
Reputation: m.asfak is an unknown quantity at this point 
Solved Threads: 0
m.asfak m.asfak is offline Offline
Newbie Poster
 
0
  #4
Oct 21st, 2009
Let's make an example that is similar to you

XML, XSLT and XPATH Syntax (Toggle Plain Text)
  1. <abc>
  2. <def>
  3. <img>1</img>
  4. <img>2</img>
  5. <img>3</img>
  6. </def>
  7. <ghi>
  8. <img>4</img>
  9. </ghi>
  10. <jkl/>
  11. </abc>

Now my code will be

XML, XSLT and XPATH Syntax (Toggle Plain Text)
  1. <xsl:template match="/">
  2. <xsl:for-each select="//img[preceding-sibling::img or following-sibling::img]">
  3. <xsl:value-of select="."></xsl:value-of>
  4. </xsl:for-each>
  5. </xsl:template>

Hope it will be okay.

Regards.
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 4
Reputation: jaanu123 is an unknown quantity at this point 
Solved Threads: 0
jaanu123 jaanu123 is offline Offline
Newbie Poster
 
-1
  #5
Nov 3rd, 2009
thanks for all for providing their suggestions and i was also trying for one like this
+++++++++++++++++++++++++++++
bandwidth test
Utah Web Design
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the XML, XSLT and XPATH Forum
Thread Tools Search this Thread



Tag cloud for XML, XSLT and XPATH
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC