XSL:将XML解析为HTML - 如何将元素数据的值用作html属性?

时间:2010-05-19 15:12:15

标签: html xml xslt

<input src="LOGO.JPG" type="image" name="imagem">

我有一个xml元素,其中包含需要在解析后以HTML格式显示的图像路径。 <xsl:value-of select="image"/>返回存储在图像元素中的字符串,但是如何使用它来使该字符串成为html标记中的src属性值? 我试过<input src="<xsl:value-of select="image"/>" type="image" name="imagem">,但显然这不起作用,怎么办呢?

我希望我的问题清楚。请帮忙!

3 个答案:

答案 0 :(得分:1)

<input type="image" name="imagem" src="{image}" />

答案 1 :(得分:0)

这应该有效:

<input type="image" name="imagem">
    <xsl:attribute name="src"><xsl:value-of select="image" /></xsl:attribute>
</input>

答案 2 :(得分:0)

你的意思是?:

<xsl:template select="//image">
    <xhtml:img>
        <xsl:attribute name="alt"><xsl:value-of="@name" /></xsl:attribute>
        <xsl:attribute name="src"><xsl:value-of="@src" /></xsl:attribute>
    </xhtml:img>
</xsl:template>

请记住正确绑定名称空间前缀。此外,HTML 中的img元素必须具有alt。

或者将“// image”替换为XML元素的特定Xpath。

相关问题