Xslt 和多行文本 (Sitecore)

发布于 2024-08-20 21:56:14 字数 102 浏览 4 评论 0原文

我在项目(多行文本)中有一个字段,我在 xslt 渲染中输出该字段。问题是 carrigae 返回未显示在我的输出中 - 我需要做什么才能使我的 xslt 输出显示 carrigae 返回?

I have a field in item (multi-line text) which i output in my xslt rendering. The problem is that carrigae return are not shown in my output - what do i need to do to make my xslt output show the carrigae returns?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

就像说晚安 2024-08-27 21:56:14

使用此模板替换换行符:

<xsl:template name="br">
    <xsl:param name="text"/>
    <xsl:choose>
        <xsl:when test="contains($text,'
')">
            <xsl:value-of select="substring-before($text,'
')"/>
            <br/>
            <xsl:call-template name="br">
                <xsl:with-param name="text">
                    <xsl:value-of select="substring-after($text,'
')"/>
                </xsl:with-param>
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$text"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

并在您的文本项上调用它,如下所示:

<xsl:call-template name="br">
    <xsl:with-param name="text" select="somenode/mytext"/>
</xsl:call-template>

Use this template to substitude newlines:

<xsl:template name="br">
    <xsl:param name="text"/>
    <xsl:choose>
        <xsl:when test="contains($text,'
')">
            <xsl:value-of select="substring-before($text,'
')"/>
            <br/>
            <xsl:call-template name="br">
                <xsl:with-param name="text">
                    <xsl:value-of select="substring-after($text,'
')"/>
                </xsl:with-param>
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$text"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

And call it upon your text item like this:

<xsl:call-template name="br">
    <xsl:with-param name="text" select="somenode/mytext"/>
</xsl:call-template>
放低过去 2024-08-27 21:56:14

XML 源中的回车符将被视为空格而被忽略。 (实际上,所有连续的空白字符都被压缩为一个空格。)但是,也许其中之一可以代替普通的回车符?

       <xsl:text>This text has
a newline</xsl:text>

或者

This text has
a newline

A carriage return in XML source is ignored as whitespace. (Really, all consecutive whitespace characters are condensed to one space.) However, perhaps one of these will work instead of a plain carriage return?

       <xsl:text>This text has
a newline</xsl:text>

Or

This text has
a newline
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文