我的xml文件
<entries>
<entry ID="93" ENTRY_TYPE="Text1" ENTRYNM="First line:
Second line
third line
fourth line" ENTRY_DT="12-Jan-2004"/></entries>
Run Code Online (Sandbox Code Playgroud)
我的xsl-fo
<fo:block linefeed-treatment="preserve" white-space-treatment='preserve'
white-space-collapse='false'>
<xsl:value-of select="./entries/entry/@ENTRYNM"/>
</fo:block>
Run Code Online (Sandbox Code Playgroud)
我正在生成包含ENTRYNM的pdf,它应该保留下一行,如xml所示.
Like example:
First line:
Second line
third line
fourth line
Run Code Online (Sandbox Code Playgroud)
这是因为属性值规范化.换行符被标准化为空格.保留这些的唯一方法是在属性值中使用字符引用.
例如,如果您有这个XML:
<entry ID="93" ENTRY_TYPE="Text1" ENTRYNM="First line:
Second line
third line
fourth line" ENTRY_DT="12-Jan-2004"/>
Run Code Online (Sandbox Code Playgroud)
和这个XSLT(为了简洁省略了xsl-fo命名空间):
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/*">
<block linefeed-treatment="preserve">
<xsl:value-of select="@ENTRYNM"/>
</block>
</xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)
你会得到这个输出(标准化):
<block linefeed-treatment="preserve">First line: Second line third line fourth line</block>
Run Code Online (Sandbox Code Playgroud)
如果将换行符更改为输入中的字符引用:
<entry ID="93" ENTRY_TYPE="Text1" ENTRYNM="First line:

Second line

third line

fourth line" ENTRY_DT="12-Jan-2004"/>
Run Code Online (Sandbox Code Playgroud)
相同的XSLT现在生成此输出:
<block linefeed-treatment="preserve">First line:
Second line
third line
fourth line</block>
Run Code Online (Sandbox Code Playgroud)
这是规范化的另一个视觉例子......
如果我们采用第一个XML输入示例:
<entry ID="93" ENTRY_TYPE="Text1" ENTRYNM="First line:
Second line
third line
fourth line" ENTRY_DT="12-Jan-2004"/>
Run Code Online (Sandbox Code Playgroud)
并尝试基于以下方式进行标记
:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/*">
<block linefeed-treatment="preserve">
<xsl:for-each select="tokenize(@ENTRYNM,'
')">
<token><xsl:value-of select="."/></token>
</xsl:for-each>
</block>
</xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)
我们token在输出中得到一个:
<block linefeed-treatment="preserve">
<token>First line: Second line third line fourth line</token>
</block>
Run Code Online (Sandbox Code Playgroud)
如果我们使用第二个XML输入示例(将断点替换为
引用),我们得到4个单独的tokens:
<block linefeed-treatment="preserve">
<token>First line:</token>
<token> Second line</token>
<token> third line</token>
<token> fourth line</token>
</block>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4846 次 |
| 最近记录: |