问题
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() < 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?
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