xml 如何在 xslt 输出的末尾添加换行符?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13239446/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 13:45:23  来源:igfitidea点击:

how to add line breaks at the end of an xslt output?

xmlxslt

提问by user1800825

Possible Duplicate:
Producing a new line in XSLT

可能的重复:
在 XSLT 中生成一个新行

if have the following xslt file:

如果有以下 xslt 文件:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <xsl:output method="text" />
    <xsl:template match="//teilnehmer">
        <xsl:value-of select="name"/>
        <xsl:value-of select="kind"/>
    </xsl:template>
</xsl:stylesheet>

the output after transformation is a string without any whitespaces or line breaks

转换后的输出是一个没有任何空格或换行符的字符串

how can I add some formatting (e.g. a line break after a name)?

如何添加一些格式(例如名称后的换行符)?

thanks in advance!

提前致谢!

回答by Ian Roberts

The easiest way is with

最简单的方法是

<xsl:text>&#x0A;</xsl:text>

&#x0A;being a character reference that represents the newline character. Alternatively you can do

&#x0A;作为表示换行符的字符引用。或者你可以做

    <xsl:text>
</xsl:text>

(i.e. an <xsl:text>containing just a newline character) but you need to ensure there are no spaces between the newline and the closing </xsl:text>(as they would be included in the output), which is easy to mess up if you ever use an IDE that does automatic indentation. Using the character reference is more robust.

(即<xsl:text>只包含一个换行符)但您需要确保换行符和结束符之间没有空格</xsl:text>(因为它们将包含在输出中),如果您使用自动执行的 IDE,这很容易搞砸缩进。使用字符引用更加健壮。