开发者

XSL: Parsing XML to HTML - How do I use value-of an element data as an html attribute?

开发者 https://www.devze.com 2022-12-30 16:56 出处:网络
<input src=\"LOGO.JPG\" type=\"image\" name=\"imagem\"> I have an xml element that contains the image path that needs to be displayed in HTML after the parse.
<input src="LOGO.JPG" type="image" name="imagem">

I have an xml element that contains the image path that needs to be displayed in HTML after the parse. <xsl:value-of select="image"/> returns the string that is stored in the image element but how can I use it to make that string be the src atribute value in an html tag? I tried <input src="<xsl:value-of select="image"/>" type="image" name="imagem"> but obviously that doesn't work 开发者_开发技巧so how can it be done?

I hope I was clear in my question. Please help!


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


Do you mean?:

<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>

Remember to bind the namespace prefixes correctly. Also, img elements in HTML must have an alt.

alternatively replace "//image" with the specific Xpath to your XML element.


This should work:

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

精彩评论

暂无评论...
验证码 换一张
取 消