XSL-FO在每个节点之后添加新行 [英] XSL-FO add new line after each node
问题描述
我有一个具有如下结构的XML文件:
I have an XML file with structure like this:
<parent>
<node>Text 1</node>
<node>Text 2</node>
<node>Text 3</node>
<node>Text 4</node>
<node>Text 5</node>
</parent>
我想用XSL-FO处理该XML以产生PDF输出.我有以下XSL-FO模板:
I want to process this XML with XSL-FO to produce PDF output. I have following XSL-FO template:
<fo:block>
<xsl:for-each select="node[position() < last()]">
<xsl:value-of select="."/>
<xsl:if test="position() != last()">
<xsl:text>
</xsl:text>
</xsl:if>
</xsl:for-each>
</fo:block>
这似乎行不通.我得到内联输出,而不是它自己的行中的每个节点.我该如何解决这个问题?
It seems that this doesn't work well. I get output inline, instead of each node in it's own line. How can I resolve this problem?
谢谢!
推荐答案
如果在node元素上进行匹配并为它们创建fo:block,则可以更好地控制事物.您拥有的解决方案是将它们放入内联中,另一个答案可以解决,但对它们的控制较少.
You would have better control of things if you matched on the node element and created an fo:block for them. The solution you have is for putting them inline, the other answer will work but yield less control of them.
如果您希望每个人都换行(这意味着您想要一个新的街区),则将每个人都放在自己的街区中.
If you want each one in a new line (which means you want a new block area), then put each one is it's own block.
这意味着,您将在XSL中执行以下操作:
Meaning, you would do somewhere in your XSL:
<xsl:template match="node">
<fo:block>
<xsl:apply-templates/>
</fo:block>
</xsl:template>
您应该没有理由使用value-of select =.".上面的代码将为您做到这一点,并且如果您将其扩展到在node元素中包含某些内容,那么您的所有内容都将全部设置好.
There should be no reason for you to use value-of select=".". The above will do that for you and if you ever expand to have something inside of the node element, then your are still all set.
这篇关于XSL-FO在每个节点之后添加新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!