How to implement Carriage return in XSLT

后端 未结 10 1326
甜味超标
甜味超标 2020-12-28 15:18

I want to implement carriage return within xslt. The problem is I have a varible: Step 1 = Value 1 breaktag Step 2 = Value 2 as a string and would like to appear as

相关标签:
10条回答
  • 2020-12-28 15:50

    I believe that you can use the xsl:text tag for this, as in

    <xsl:text>
    </xsl:text>
    

    Chances are that by putting the closing tag on a line of its own, the newline is part of the literal text and outputted as such.

    0 讨论(0)
  • 2020-12-28 15:51

    I was looking for a nice solution to this, as many would prefer, without embedding escape sequences directly in the expressions, or having weird line breaks inside of a variable. I found a hybrid of both this approaches actually works, by embedding a text node inside a variable like this:

    <xsl:variable name="newline"><xsl:text>&#10;</xsl:text></xsl:variable>
    <xsl:value select="concat(some_element, $newline)" />
    

    Another nice side-affect of this is that you can pass in whatever newline you want, be it just LF, CR, or both CRLF.

    --Daniel

    0 讨论(0)
  • 2020-12-28 16:00

    use a simple carriage return in a xsl:text element

    <xsl:text>
    </xsl:text>
    
    0 讨论(0)
  • 2020-12-28 16:02

    Try this at the end of the line where you want the carriage return. It worked for me.

    <xsl:text><![CDATA[<br />]]></xsl:text>
    
    0 讨论(0)
  • 2020-12-28 16:05

    I separated the values by Environment.NewLine and then used a pre tag in html to emulate the effect I was looking for

    0 讨论(0)
  • 2020-12-28 16:06

    As an alternative to

    <xsl:text>
    </xsl:text>
    

    you could use

    <xsl:text>&#10;</xsl:text> <!-- newline character -->
    

    or

    <xsl:text>&#13;</xsl:text> <!-- carriage return character -->
    

    in case you don't want to mess up your indentation

    0 讨论(0)
提交回复
热议问题