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() > 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.
精彩评论