Search code examples
objective-cxpathtfhpple

Xpath getting multiple img's in div


I'm working with TFHpple and I would like to get all of the image url's in a single div tag, the number of images can very so it would need to be dynamic. Here is the HTML

<div id="images" class="content">
      <div class="galleria">
<img data-thumb="https://s3.amazonaws.com/nakedapartments/images/78659582/mthumb.jpg?1453414352" alt="" class="hidden" src="https://s3.amazonaws.com/nakedapartments/images/78659582/large.jpg?1453414352" />

<img data-thumb="https://s3.amazonaws.com/nakedapartments/images/78659608/mthumb.jpg?1453414354" alt="" class="hidden" src="https://s3.amazonaws.com/nakedapartments/images/78659608/large.jpg?1453414354" />

<img data-thumb="https://s3.amazonaws.com/nakedapartments/images/78659634/mthumb.jpg?1453414356" alt="" class="hidden" src="https://s3.amazonaws.com/nakedapartments/images/78659634/large.jpg?1453414356" />
</div>
    </div>

So far I've only been able to fetch the first one and adding the src to an array using this path:

//div[@class='content']/div[@class='galleria']/img

Can any one point me in the right direction for getting all src attributes that exist in the div into my array? Thank you!


Solution

  • The XSLT template for satisfying this task would be

    <xsl:template match="//div[@class='content']/div[@class='galleria']/img">
        <xsl:value-of select="@src" />
    </xsl:template>
    

    The according XPath-Expression for getting the values of all src-attributes would be

    //div[@class='content']/div[@class='galleria']/img/@src
    

    That should get you all the required values of the src-attributes, but in XSLT this doesn't work - for a reason that is unknown to me. Maybe someone has an idea?