转换后如何防止自关闭标签以及空标签 [英] How to prevent self closing tags as well empty tags after transforming

查看:38
本文介绍了转换后如何防止自关闭标签以及空标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个输入文件:

<a></a>
<b/>
<c>text</c>

我需要将其转换为字符串.使用变压器我得到低于输出:

I need to converting this to string. Using transformer I am getting below output:

<a/> <!-- Empty tags should not collapse-->
<b/>
<c>text</c>

如果我使用 xslt 并且输出方法是HTML",我会得到以下输出:

If I use xslt and output method is "HTML", I get the below output:

<a></a> <!-- This is as expected-->
<b></b> <!-- This is not expected-->
<c>text</c>

我想要与输入文件相同的结构.我的应用中需要它,因为我需要计算索引,并且很难更改索引计算逻辑.

I want the structure same as in input file. It is required in my application since I need to calculate index and it will be very difficult to change the index calution logic.

什么是正确的 XSLT 使用?

What would be the correct XSLT to use?

推荐答案

一个可能的替代方法是像这样使用 disable-output-escaping:

A possible alternative is to use disable-output-escaping like this:

<xsl:text disable-output-escaping="yes">&lt;a&gt;&lt;/a&gt;</xsl:text>

但我知道这是一个肮脏的解决方案......

But I understand that this is a dirty solution...

这篇关于转换后如何防止自关闭标签以及空标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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