如何在 XSLT 中呈现带有属性的自关闭 HTML 标记? [英] How to render a self closing HTML tag with attributes in XSLT?

查看:32
本文介绍了如何在 XSLT 中呈现带有属性的自关闭 HTML 标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我想渲染一个自关闭标签,比如 <img> 标签,就像这样 <img src="xyz.jpg"/>

Well I want to render a self closing tag say <img> tag like this <img src="xyz.jpg" />

但我不知道该怎么做...我的意思是如何呈现自关闭标签.到目前为止,我所拥有的如下:-

But I don't know how to do that...I mean how to render a self closing tag. What I'm having so far is below:-

这里是 XML:

<c:Image src="xyz.jpg"></c:Image>

这里是 XSLT:

<xsl:output indent="yes" omit-xml-declaration="yes" method="html"  />
.
.
.
    <xsl:for-each select="c:Image">
     <img>
      <xsl:attribute name="src">
        <xsl:if test="string-length(@src)>0">
          <xsl:text></xsl:text>
          <xsl:value-of select="@src"/>
        </xsl:if>
        </xsl:attribute>
     </img>
    </xsl:for-each>
.
.
.

感谢任何帮助.

推荐答案

有一个肮脏的方法:欺骗"处理器并产生一个字符串

There is a dirty way for this: "fooling" the processor and producing a string

<xsl:for-each select="c:Image">
  <xsl:text disable-output-escaping="yes">&lt;img src="</xsl:text>
  <xsl:value-of select="@src" />
  <xsl:text disable-output-escaping="yes">" /&gt;</xsl:text>
</xsl:for-each>  

好吧,我同意这是一个可怕的技巧,但它适用于所有 proc.

OK, I agree that it's an awful trick, but it works with all proc.

这篇关于如何在 XSLT 中呈现带有属性的自关闭 HTML 标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆