Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

xml

xslt

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!

like image 452
user1800825 Avatar asked Jan 29 '26 17:01

user1800825


1 Answers

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.

like image 160
Ian Roberts Avatar answered Feb 01 '26 11:02

Ian Roberts



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!