xml - linefeed-treatment="preserve" not working for next line generating pdf via xsl-fo -


my xml file

<entries>  <entry id="93" entry_type="text1" entrynm="first line:   second line   third line   fourth line" entry_dt="12-jan-2004"/></entries> 

my xsl-fo

<fo:block linefeed-treatment="preserve" white-space-treatment='preserve'       white-space-collapse='false'> <xsl:value-of select="./entries/entry/@entrynm"/> </fo:block> 

i generating pdf contains entrynm should preserve next line shown in xml.

like example: first line: second line third line fourth line 

this because of attribute value normalization. line breaks getting normalized spaces. way preserve these use character reference in attribute value.

for example, if have xml:

<entry id="93" entry_type="text1" entrynm="first line:     second line     third line     fourth line" entry_dt="12-jan-2004"/> 

and xslt (omitted xsl-fo namespace brevity):

<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> 

you output (normalized):

<block linefeed-treatment="preserve">first line:     second line     third line     fourth line</block> 

if change line breaks character references in input:

<entry id="93" entry_type="text1" entrynm="first line:&#xa;     second line&#xa;     third line&#xa;     fourth line" entry_dt="12-jan-2004"/> 

the same xslt produces output:

<block linefeed-treatment="preserve">first line:      second line      third line      fourth line</block> 

here's visual example of normalization...

if take first xml input example:

<entry id="93" entry_type="text1" entrynm="first line:     second line     third line     fourth line" entry_dt="12-jan-2004"/> 

and try tokenize based on &#xa;:

<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,'&#xa;')">                 <token><xsl:value-of select="."/></token>             </xsl:for-each>         </block>     </xsl:template>  </xsl:stylesheet> 

we single token in output:

<block linefeed-treatment="preserve">    <token>first line:     second line     third line     fourth line</token> </block> 

if use second xml input example (with breaks replaced &#xa; references), 4 separate tokens:

<block linefeed-treatment="preserve">    <token>first line:</token>    <token>     second line</token>    <token>     third line</token>    <token>     fourth line</token> </block> 

Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -