2013-03-22 59 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