0

Hi all

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

<p>
  <img ../>
  <img ../>
  <img ../>
</p>
<p>
  <img ../>
</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

3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by m.asfak
0
var siblings=[]
for( var i=0, limit=document.images.length-1; ++i)
{
 if( document.images[i].parentNode===document.images[i+1].parentNode)
 siblings[siblings.length]=i;
}
alert( siblings.join("\n") );
0

sorry, the for clause should be

for( var i=0, limit=document.images.length-1; i < limit; ++i)
...
0

Let's make an example that is similar to you

<abc>
    <def>
        <img>1</img>
        <img>2</img>
        <img>3</img>
    </def>
    <ghi>
        <img>4</img>
    </ghi>
    <jkl/>
</abc>

Now my code will be

<xsl:template match="/">
        <xsl:for-each select="//img[preceding-sibling::img or following-sibling::img]">
            <xsl:value-of select="."></xsl:value-of>
        </xsl:for-each>
    </xsl:template>

Hope it will be okay.

Regards.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.