簡體   English   中英

XSL:將XML解析為HTML-如何使用元素數據的值作為html屬性?

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

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

我有一個xml元素,其中包含需要在解析后以HTML顯示的圖像路徑。 <xsl:value-of select="image"/>返回存儲在image元素中的字符串,但是我如何使用它使該字符串成為html標記中的src屬性值? 我嘗試了<input src="<xsl:value-of select="image"/>" type="image" name="imagem">但顯然這不起作用,怎么辦?

我希望我的問題很清楚。 請幫忙!

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

這應該工作:

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

你的意思是?:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM