EnexoOnoma
EnexoOnoma

Reputation: 8834

Simple XSLT modification to get the img src of a tag

In the <content> tag of a XML among others, there is a

<img style="styles" src="image.jpg" border="0" alt=""> image I want to get the src.

As for now I add an attribute img to the content tag that gets the entire content.

How can I get the image src ?

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  xmlns:a="http://www.w3.org/2005/Atom"  >

    <xsl:include href="identity.xsl"/>

<xsl:template match="a:feed/a:entry/a:content">
<content img="{img/@src}"> 
  <xsl:apply-templates/> 
</content>
</xsl:template>

<xsl:template match="a:entry[position() &gt; 1]" />

</xsl:stylesheet>

Upvotes: 2

Views: 725

Answers (1)

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243549

Use:

<content img="{img/@src}"> 
  <xsl:apply-templates/> 
</content>

When you know that img is a child of the current node, there is no need to wite an absolute Xpath expression -- the relative XPath expression (img/@src) is evaluated off the current node.

Upvotes: 1

Related Questions