如何解决在生成的 PDF 中保留原始段落
经过多次尝试,我无法从“SOME_PARAGRAPHS”路径生成尊重原始段落或加载文本的 pdf。
任何提示将不胜感激。
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="xml" encoding="ISO-8859-1" doctype-public="-//big.faceless.org//report" />
<xsl:template match="INFORMEMEDICO">
<pdf>
<head>
</head>
<body size="A4" header-height="15mm" footer-height="15mm">
<br/>
<!-- A (not show) -->
<fo:block linefeed-treatment="preserve"><xsl:value-of select="SOME_PARAGRAPHS"/></fo:block>
<br/>
<!-- B (show but without respecting original paragraphs) -->
<p><xsl:value-of select="SOME_PARAGRAPHS"/></p>
<pbr/>
</body>
</pdf>
</xsl:template>
</xsl:stylesheet>
...具有:
<SOME_PARAGRAPHS>
Candy cookie topping cotton candy icing pastry tart danish dessert.
Icing carrot cake gingerbread candy powder muffin soufflé fruitcake sweet roll.
Wafer toffee topping jelly-o sesame snaps oat cake pie marzipan lemon drops.
</SOME_PARAGRAPHS>
这里没有“SOME_PARAGRAPHS”参与的简化版:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="xml" encoding="ISO-8859-1"
doctype-public="-//big.faceless.org//report" />
<xsl:template match="INFORMEMEDICO">
<pdf>
<head>
</head>
<body size="A4" header-height="15mm" footer-height="15mm">
<br/>
<!-- (not show) -->
<fo:block linefeed-treatment="preserve">
Candy cookie topping cotton candy icing pastry tart danish dessert.
Icing carrot cake gingerbread candy powder muffin soufflé fruitcake sweet roll.
Wafer toffee topping jelly-o sesame snaps oat cake pie marzipan lemon drops.
</fo:block>
<br/>
<pbr/>
</body>
</pdf>
</xsl:template>
</xsl:stylesheet>
解决方法
代替:
<xsl:value-of select="SOME_PARAGRAPHS"/>
您可能想要:
<xsl:apply-templates select="SOME_PARAGRAPHS"/>
然后你需要处理那些 SOME_PARAGRAPHS
之类的模板
<xsl:template match="SOME_PARAGRAPHS">
<fo:block linefeed-treatment="preserve">
<xsl:apply-templates select="@*|node()"/>
</fo:block>
</xsl:template>
我建议从 xsl intro
开始如果您熟悉 xsl,请执行 intro xsl-fo
,我已经能够通过在Java后端分解段落来解决它:
StringTokenizer textoDictamenVidaLineas = new StringTokenizer(textoDictamenVida,"\n");
String linea;
while (textoDictamenVidaLineas.hasMoreTokens()) {
linea = textoDictamenVidaLineas.nextToken();
documentoXML.append("<SOME_PARAGRAPHS>" + linea + "</SOME_PARAGRAPHS>\n");
}
并在模板中使用它:
<xsl:for-each select="SOME_PARAGRAPHS">
<p><xsl:value-of select="."/></p>
</xsl:for-each>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。