开发者

Simple XSLT modification to get the img src of a tag

开发者 https://www.devze.com 2023-04-10 12:39 出处:网络
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.

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>


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消