用 xsl:text 解释换行符? [英] Interpreting newlines with xsl:text?

查看:37
本文介绍了用 xsl:text 解释换行符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 XSL 样式表,其内容位于 xsl:text 节点中,如下所示:

I have an XSL stylesheet with content in an xsl:text node like this:

<xsl:text>
foo
bar
baz
</xsl:text>

样式表本身是一个带有unix 风格"换行符的文本文件.我在 Windows 以及类 Unix 平台上调用此样式表.如果输出符合调用它的平台的约定,那就太好了.

The stylesheet itself is a text file with "unix-style" newline line terminators. I invoke this stylesheet on Windows as well as unix-like platforms. It would be nice to have the output conform to the conventions of the platform on which it is invoked.

当我在 Windows 上运行此样式表时,输出具有回车/换行符对,除了xsl:text 节点的内容.

When I run this stylesheet on Windows, the output has carriage return/newline pairs for everything except the contents of the xsl:text node.

我可以指示 XSLT 处理器将 xsl:text 节点内容中的换行符转换为特定于平台的行尾吗?

Can I instruct the XSLT processor to translate the newline characters in the content of the xsl:text node into platform specific end-of-lines?

更多上下文:我正在从 Apache Ant 1.7.1 XSLT 任务调用样式表 像这样:

More context: I'm invoking the stylesheet from the Apache Ant 1.7.1 XSLT task like this:

<xslt in="in.xml" out="out.xml" style="stylesheet.xsl"/>

当前的样式表标题如下所示:

The stylesheet header currently looks like this:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xalan="http://xml.apache.org/xslt"
    exclude-result-prefixes="xalan">
    <!-- contents elided -->
</xsl:stylesheet>

推荐答案

您可以像这样为样式表定义一个参数:

You could define a parameter for the stylesheet like so:

<xsl:param name="br">
    <xsl:text>&#10;</xsl:text>
</xsl:param>

并通过在 Ant 脚本中使用嵌套的 param 元素传入适当的行尾字符.当然,此示例中的默认值将是 Unix 样式的换行符.我认为要输出该值,您必须使用:

and pass in the appropriate end of line character(s) by using a nested param element in your Ant script. The default in this example would be a Unix-style newline, of course. I think to output the value, you'd have to use:

<xsl:copy-of select="$br"/>

虽然冗长,但确实有效.

It's verbose, but it works.

这篇关于用 xsl:text 解释换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆