2013-03-22 60 views
1

我需要使用xslt有关xml RSS提要的信息进行显示。 XML源是:将图像从CDATA-xml rss文件提取到xslt中

<description><![CDATA[<p> 
<img style="margin: 10px; 
    float: left;" alt="Nuevo modelo general de negocio" 
    src="http://mysite.es/images/figure1.jpg" width="196" height="147" /> 
    La compañía apuesta por un marcado giro en el modelo]]> 
</description> 

I'm使用:

<xsl:value-of select="description" disable-output-escaping="yes"/> 

但呈现并不好,因为我需要表现出调整大小的图像,具有尺寸,例如70x70。

从来就试着用这个,但它的错误:

<xsl:value-of select="replace("description","images/","images/resized/images/")" 
    disable-output-escaping="yes"/> 

对我来说,完美的解决方案。将提取物中分离,既src属性和标签中的文字。

问候, 玛丽亚

+0

请参阅答案这里http://stackoverflow.com/questions/8273065/xml-xsl-transformation-with-cdata – Treemonkey 2013-03-22 10:11:52

+0

您可以使用XSLT 3.0(XPath 3.0)轻松完成此操作。您对XSLT 3.0解决方案感兴趣吗?或者,对于.NET XslCompiledTransform使用我在这里描述的技术:http://stackoverflow.com/a/8273277/36305 – 2013-03-22 14:57:01

+0

对不起,我是新的xslt,我不能给你的问题的回应...我是在Sharepoint Foundation 2010中创建一个webpart。 – mpl 2013-03-23 11:06:27

回答

0

如果您的XML总是喜欢你的例子,那么你应该能够使用这样的事情:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
exclude-result-prefixes="xsl"> 

    <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/> 

    <xsl:template match="/"> 
    <div> 
     <xsl:apply-templates select="rss/channel"/> 
    </div> 
    </xsl:template> 
    <xsl:template match="rss/channel"> 
    <ul> 
     <xsl:apply-templates select="item"/> 
    </ul> 
    </xsl:template> 
    <xsl:template match="item"> 
    <xsl:variable name="item_link" select="link"/> 
    <xsl:variable name="item_title" select="substring-after(description, '/&gt;')"/> 
    <xsl:variable name="item_image" select="substring-before(substring-after(description, 'src=&quot;'), '&quot;')" /> 
    <li> 
     <a href="{$item_link}"> 
     <img alt="" src="{$item_image}" width="70" height="70" /> 
     <xsl:value-of select="$item_title"/> 
     </a> 
    </li> 
    </xsl:template> 
</xsl:stylesheet> 
+0

完美的每一个,你的代码我可以读取src attibute没有问题...谢谢 – mpl 2013-05-28 16:21:36