如何将换行符添加到使用XSLT创建的文本中?

时间:2022-02-22 18:53:24

I am trying to create text output from an xml file using xslt. It is actually an xslt that creates SQL code. Here is a part that outputs CREATE TABLE statements:

我正在尝试使用xslt从xml文件创建文本输出。它实际上是一个创建SQL代码的xslt。下面是输出CREATE TABLE语句的部分:

CREATE TABLE dbo.[<xsl:value-of select="@PhysicalName"/>] (
  <xsl:for-each select="EntityAttributes/EntityAttribute">
    <xsl:apply-templates select="Attributes/Attribute[@AttributeID = current()/@EntityAttributeID]"/> ...
  </xsl:for-each>)

I want to have a line break after the "(" in the first line but cannot manage to find out how to do so. Can anyone help?

我希望在“(”在第一行之后有一个换行符,但是无法找到如何这样做的方法。谁能帮忙吗?

3 个解决方案

#1


11  

If you put

如果你把

<xsl:text>
</xsl:text>

in your XSLT it will give a line break. It is not clear where you wish to put this. I am guessing you want:

在您的XSLT中,它将给出换行符。现在还不清楚你想把它放在哪里。我猜你想要:

<xsl:text>CREATE TABLE dbo.[</xsl:text><xsl:value-of select="@PhysicalName"/><xsl:text>] (
</xsl:text>

In general you should always wrap text output in ... it looks slightly horrid in the XSL but it preserves the spacing. Note that you can break the lines in the XSLT without affecting the result - e.g.

一般来说,你应该在……在XSL中看起来有点可怕,但它保留了间距。注意,您可以在不影响结果的情况下破坏XSLT中的行—例如。

<xsl:text>CREATE TABLE dbo.[</xsl:text>
<xsl:value-of select="@PhysicalName"/>
<xsl:text>] (&#xa;</xsl:text>

and yes, I agree about the explicit line break character. As you can see the XSLT is not very readable but it gets the right answer

是的,我同意明确的断行字符。正如您所看到的,XSLT不是很好读,但是它得到了正确的答案

#2


33  

As for line breaks, I myself prefer more explicit/readable way.

至于换行,我个人更喜欢更明确的/可读的方式。

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

#3


-2  

use tags it's easy

使用标签很容易

Example:
<div>TOTAL STAR POINTS EARNED </div>
<div>TOTAL STAR POINTS REDEEMED </div>
<div>BALANCE STAR POINTS AVAILABLE </div>

output:

输出:

TOTAL STAR POINTS EARNED 
TOTAL STAR POINTS REDEEMED 
BALANCE STAR POINTS AVAILABLE 

#1


11  

If you put

如果你把

<xsl:text>
</xsl:text>

in your XSLT it will give a line break. It is not clear where you wish to put this. I am guessing you want:

在您的XSLT中,它将给出换行符。现在还不清楚你想把它放在哪里。我猜你想要:

<xsl:text>CREATE TABLE dbo.[</xsl:text><xsl:value-of select="@PhysicalName"/><xsl:text>] (
</xsl:text>

In general you should always wrap text output in ... it looks slightly horrid in the XSL but it preserves the spacing. Note that you can break the lines in the XSLT without affecting the result - e.g.

一般来说,你应该在……在XSL中看起来有点可怕,但它保留了间距。注意,您可以在不影响结果的情况下破坏XSLT中的行—例如。

<xsl:text>CREATE TABLE dbo.[</xsl:text>
<xsl:value-of select="@PhysicalName"/>
<xsl:text>] (&#xa;</xsl:text>

and yes, I agree about the explicit line break character. As you can see the XSLT is not very readable but it gets the right answer

是的,我同意明确的断行字符。正如您所看到的,XSLT不是很好读,但是它得到了正确的答案

#2


33  

As for line breaks, I myself prefer more explicit/readable way.

至于换行,我个人更喜欢更明确的/可读的方式。

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

#3


-2  

use tags it's easy

使用标签很容易

Example:
<div>TOTAL STAR POINTS EARNED </div>
<div>TOTAL STAR POINTS REDEEMED </div>
<div>BALANCE STAR POINTS AVAILABLE </div>

output:

输出:

TOTAL STAR POINTS EARNED 
TOTAL STAR POINTS REDEEMED 
BALANCE STAR POINTS AVAILABLE