在我的XML文档中,我正在提取A的内容 <TextBlock> 其中包含图像。 XML显示:

<img src="/templates_soft/images/facebook.png" alt="twitter" />

当我查看页面时,图像不会显示,因为它与原始页面不在相同的路径上。

我需要添加其余的URL以显示要显示的图像。就像是 http://www.mypage.com/ 使图像显示 http://www.mypage.com/templates_soft/images/facebook.png

有没有办法做到这一点?

有帮助吗?

解决方案

利用:

<img src="{$imageBase/}templates_soft/images/facebook.png" alt="twitter" />

xsl:nater命名的位置 $imageBase 被定义为包含必要的前缀(在您的情况下 "http://www.mypage.com").

这是一个完整的XSLT解决方案:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:param name="pimageBase" select="'http://www.mypage.com'"/>

    <xsl:template match="img">
   <img src="{concat($pimageBase, @src)}" alt="{@alt}"/>
  </xsl:template>
</xsl:stylesheet>

当在以下XML文档上应用此转换时:

<img src="/templates_soft/images/facebook.png" alt="twitter" />

想要的,正确的结果被产生:

<img src="http://www.mypage.com/templates_soft/images/facebook.png" alt="twitter"/>

其他提示

如果您使用XSLT,则只需创建一个XML,该XML随时随地包含整个URL,然后将其标记为XSLT,以便将其包含在XML文件中的原始字段中。如果您像网格一样绑定到控件,则可以绑定并添加信息,如果您比XSLT更容易执行此操作。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top