使用xsl:if不包含结束标记 [英] Using xsl:if doesn't include closing tag

查看:72
本文介绍了使用xsl:if不包含结束标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用以下代码将Google广告插入博客卷中

Trying to use the following code to insert a google ad inside of a blog roll

<xsl:if test="position() = 3">
    <object data="/frontpage_blogroll_center_top_728x90" 
            width="735" 
            height="95"  ></object>
</xsl:if>  

由于某种原因,结束标记</object> 不能在HTML中呈现,并导致错误.反正有解决办法吗?

For some reason the closing tag </object> doesn't get rendered in the HTML and causes error. Is there anyway to resolve this?

推荐答案

之间,XML之间没有区别(词法除外):

<object></object>

<object/>

这些表示完全相同的XML元素,并且选择了上面两种表示中的任意一种,都可以使用不同的XSLT处理器.

These represent exactly the same XML element, and different XSLT processors are free whichever of the two representations above they choose.

如果HTML中确实需要元素的长格式,则可以通过以下任一方式实现:

  • 使用< xsl:output method ="xhtml"/> . xhtml 方法仅在XSLT 2.0中可用.

  • Using <xsl:output method="xhtml"/> . The xhtml method is only available in XSLT 2.0.

使用< xsl:output method ="html"/> .XSLT转换的结果将是一个HTML文档(不是XML).

Using <xsl:output method="html"/> . The result of the XSLT transformation will be an HTML document (not XML).

使用技巧,例如:

<object data="/frontpage_blogroll_center_top_728x90" width="735" height="95"  >
  <xsl:value-of select="$vsomeVar"/>
</object>

其中 $ vsomeVar 没有任何值,并且不会导致任何输出,但是会诱使XSLT处理器认为输出了 并由此输出长格式的元素.

where $vsomeVar has no value and will not cause anything to be output, but will trick the XSLT processor into thinking something was output and thus outputting the long form of the element.

这篇关于使用xsl:if不包含结束标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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