在xsl方法中自我关闭标签:xml [英] Self closing tags in xsl method: xml

查看:119
本文介绍了在xsl方法中自我关闭标签:xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用xsl method:xml创建html模板的网站。但是,当html页面由xsl引擎呈现时,我遇到了标记自动关闭的问题。



< div> < / div> 转换为=> < div />



由于该方法需要保留xml,或者页面的其他组件不能正确呈现,这个问题更加复杂。



有关如何让xsl为节点< div> 创建特殊例外的任何想法?



这个问题与这个问题类似,只是我想保留这个方法:xml。
XSLT自动关闭标签问题

解决方案

默认情况下,method = xml不可用。您可以通过以下几种方式处理它:

选项1 - 切换到method = xhtml



如果您无法切换到method = xml,并且您使用的是XSLT 2.0分析器,那么您可以尝试method = xhtml?

 < xsl:output method =xhtmlindent =yes/> 

这会让您的结束标记被渲染。

选项2 - 为'div'标记添加空白 添加< xsl:text> < / xsl:text> (在标签之间有一个空格)使< div> 不为空(当然,没关系)。



考虑以下XML:

 < div>< / DIV> 

转化为:

 <?xml version =1.0encoding =UTF-8?> 
< xsl:stylesheet xmlns:xsl =http://www.w3.org/1999/XSL/Transformversion =1.0>

<! - output is xml - >
< xsl:output method =xmlindent =yes/>

< xsl:template match =div>
< div>
<! - 此处留意空间 - >
< xsl:text> < / XSL:文本>
< xsl:value-of select =text()/>
< / div>
< / xsl:template>
< / xsl:stylesheet>

它会产生输出:

 <?xml version =1.0encoding =UTF-8?> 
< div> < / DIV>


I am working with a site that uses "xsl method:xml" to create html templates. However, I am running into an issue with the tag self-closing when the html page is rendered by the xsl engine.

<div></div> transforms to => <div/>

This problem is compounded by the fact that the method needs to stay xml, or the other components of the page will not render correctly.

Any ideas on how tell xsl to make a special exception for the node <div>?

This question is similar to this question, except I want to keep the method:xml. XSLT self-closing tags issue

解决方案

It is not available by default with method=xml. You can handle it in a couple of ways:

Option 1 - switch to method=xhtml

If you can't switch to method=xml, and you are using XSLT 2.0 parser, maybe you can try method=xhtml?

<xsl:output method="xhtml" indent="yes" />

This will make your closing tags to be rendered.

Option 2 - add empty space to 'div' tag

Alternatively just add <xsl:text> </xsl:text> (with one space in between tags) to make your <div> not empty (of course if space there is okay with you).

Consider following XML:

<div></div>

When transformed with:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

  <!-- output is xml -->
  <xsl:output method="xml" indent="yes" />

  <xsl:template match="div">
    <div>
      <!-- note space here -->
      <xsl:text> </xsl:text>
      <xsl:value-of select="text()" />
    </div>
  </xsl:template>
</xsl:stylesheet>

It produces output:

<?xml version="1.0" encoding="UTF-8"?>
<div> </div>

这篇关于在xsl方法中自我关闭标签:xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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