how to add line breaks at the end of an xslt outpu

2019-07-04 22:00发布

问题:

Possible Duplicate:
Producing a new line in XSLT

if have the following xslt file:

<?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!

回答1:

The easiest way is with

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

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

    <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.



标签: xml xslt