XSL-FO add new line after each node

回眸只為那壹抹淺笑 提交于 2019-12-08 13:26:45

问题


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>

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() &lt; last()]">
        <xsl:value-of select="."/>
        <xsl:if test="position() != last()">
            <xsl:text>&#xA;</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?

Thanks!


回答1:


use

<fo:block  linefeed-treatment="preserve">



回答2:


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.

Meaning, you would do somewhere in your XSL:

 <xsl:template match="node">
     <fo:block>
         <xsl:apply-templates/>
     </fo:block>
 </xsl:template>

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.



来源:https://stackoverflow.com/questions/24930520/xsl-fo-add-new-line-after-each-node

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!