You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by "Gregan, Miroslav" <mi...@siemens.com> on 2007/02/13 08:46:23 UTC

XSL - NewLine

Hello all,
 
I need to put manually new line in a pdf document and it has to be for
the @value field.
I know, to put a new line I should use a new block, but Is it possible
to put some kind of "\r\n" string into the value to format it?
<fo:block hyphenate="true" font-size="10pt" font-weight="bold">
    <xsl:value-of select="@value"/>
</fo:block>

This XSL document is used to convert an XML document to PDF with either
FOP 0.20.5 or 0.93 used embedded in a java 5.0 code.
 
Thank you for your help.
 
Kind regards,
 
Miroslav Gregan
 
Siemens PSE-SK KB SK2
Dubravska cesta 4
84104 Bratislava
Slovakia
 

Re: XSL - NewLine

Posted by Stefan Heuer <sh...@gmx.de>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
 
Hi Miroslav,

I used:
<xsl:value-of select="codepoints-to-string(13)" /><xsl:value-of
select="codepoints-to-string(10)" />
for generating csv files.

Regards

Stefan


Gregan, Miroslav schrieb:
> Hello all,
> 
> I need to put manually new line in a pdf document and it has to be
> for the @value field.
> I know, to put a new line I should use a new block, but Is it
> possible to put some kind of "\r\n" string into the value to format it?
>
> <fo:block hyphenate="true" font-size="10pt" font-weight="bold">
>     <xsl:value-of select="@value"/>
> </fo:block>
>
> This XSL document is used to convert an XML document to PDF with
> either FOP 0.20.5 or 0.93 used embedded in a java 5.0 code.
> 
> Thank you for your help.
> 
> Kind regards,
> 
> Miroslav Gregan
> 
> Siemens PSE-SK KB SK2
> Dubravska cesta 4
> 84104 Bratislava
> Slovakia
> 

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
 
iD8DBQFF0XUdirQ0Ts08AdMRArpcAJoCBrMUznzo0NI51vZY7+Ujszs6fgCfV6Zo
typY5uF1ctn+oPW/O3RWCWo=
=eOGB
-----END PGP SIGNATURE-----


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: XSL - NewLine

Posted by Andreas L Delmelle <a_...@pandora.be>.
On Feb 14, 2007, at 01:03, Daniel Noll wrote:

> <snip />
> (We do our own breaking by substituting <fo:block/> elements into  
> the appropriate places before running through FOP, although it  
> sounds like this attribute to make linebreaks significant may be  
> cleaner.)

FWIW: I've always considered the insertion of empty blocks more like  
a FO-hack, a way to trick the processor. Very useful trick, in some  
cases though. I've seen especially creative use of it in combination  
with conditional negative space-before or space-after (a Norman Walsh/ 
Docbook idea, IIRC)

OTOH, if you /can/ do without them --i.e. there are no properties  
specified on the block, so it's only used to emulate HTML's <br />--  
then it's always better not to use them. Reason is that the Java  
object corresponding to a fo:block is fairly large, even for empty  
blocks. The less of them, the better for the memory footprint.

On top of that, the XSL transform should become much, much simpler,  
as it becomes only a matter of adding an attribute.


Cheers,

Andreas

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: XSL - NewLine

Posted by Daniel Noll <da...@nuix.com>.
Laurent Yaish wrote:
> Why would you store data with line breaks in an XML element attribute that
> way in the first place?
> Sounds like instead of havin <tag attribute="values with line breaks" /> 
> you
> should reformat your data to be more flexible such as something like:
> <tag>
>   <attr_tag>value1</attr_tag>
>   <attr_tag>value2</attr_tag>
>   <attr_tag>value3</attr_tag>
> </tag>

Depends, maybe that isn't semantically correct for their data (it isn't 
for ours either.)

For example, take something like an email body.  It has multiple lines 
so line breaks should be formatted as linebreaks in the output, but each 
line shouldn't really be treated as a separate element since they occur 
in the same chunk of content.

(We do our own breaking by substituting <fo:block/> elements into the 
appropriate places before running through FOP, although it sounds like 
this attribute to make linebreaks significant may be cleaner.)

Daniel

-- 
Daniel Noll

Nuix Pty Ltd
Suite 79, 89 Jones St, Ultimo NSW 2007, Australia    Ph: +61 2 9280 0699
Web: http://nuix.com/                               Fax: +61 2 9212 6902

This message is intended only for the named recipient. If you are not
the intended recipient you are notified that disclosing, copying,
distributing or taking any action in reliance on the contents of this
message or attachment is strictly prohibited.

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: XSL - NewLine

Posted by Laurent Yaish <la...@gmail.com>.
Why would you store data with line breaks in an XML element attribute that
way in the first place?
Sounds like instead of havin <tag attribute="values with line breaks" /> you
should reformat your data to be more flexible such as something like:
<tag>
   <attr_tag>value1</attr_tag>
   <attr_tag>value2</attr_tag>
   <attr_tag>value3</attr_tag>
</tag>

Just my $.02

Laurent

On 2/13/07, Tobias.Soloschenko@timetoact.de <To...@timetoact.de>
wrote:
>
>
> Hello,
>
> in one of my solutions I solved the problem with the symbol font:
>
> <fo:inline font-family="Symbol">&#160;</fo:inline>
>
> Greez
>
> Tobias
>
> Manuel Mall <ma...@apache.org> wrote on 13.02.2007 14:10:35:
>
> > On Tuesday 13 February 2007 21:52, Gregan, Miroslav wrote:
> > > Thanks you for your answers
> > >
> > > Actually I afraid I did not ask my question clearly enough.
> > > The @value which is the content of an XML File's element which
> > > contains a String.
> > > This String has to be formatted (a little bit if possible :-) ) with
> > > new lines.
> > > So that the text:
> > >
> > > Mister T"NewLineChar"Hannibal Smith"NewLineChar"Looping
> > >
> > > Where "NewLineChar" should be the expected character
> > >
> > > After rendering FOP will look like in PDF format to:
> > >
> > > Mister T
> > > Hannibal Smith
> > > Looping
> > >
> > >
> > > Is it possible? Or should I find a way to use multiple blocks?
> > >
> > As mentioned in previous responses you need to add the linefeed
> > characters to the value. However, in addition you need to set the
> > property  linefeed-treatment="preserve" on the enclosing fo:block
> > otherwise the linefeeds in the text will be treated like / converted to
> > spaces and don't generate a line break.
> >
> > > Thank you.
> > >
> > > Miroslav
> > >
> > >
> > Manuel
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
> > For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
> >
>

Re: XSL - NewLine

Posted by Abel Braaksma <ab...@xs4all.nl>.
Manuel Mall wrote:
> As mentioned in previous responses you need to add the linefeed 
> characters to the value. However, in addition you need to set the 
> property  linefeed-treatment="preserve" on the enclosing fo:block 
> otherwise the linefeeds in the text will be treated like / converted to 
> spaces and don't generate a line break.
>   

Interesting. I use xsl-fo too little to be aware of that. Nice tip for 
me as well, may save a lot of work ;)

-- Abel

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: XSL - NewLine

Posted by To...@TIMETOACT.DE.
Hello,

in one of my solutions I solved the problem with the symbol font:

<fo:inline font-family="Symbol">&#160;</fo:inline>

Greez

Tobias

Manuel Mall <ma...@apache.org> wrote on 13.02.2007 14:10:35:

> On Tuesday 13 February 2007 21:52, Gregan, Miroslav wrote:
> > Thanks you for your answers
> >
> > Actually I afraid I did not ask my question clearly enough.
> > The @value which is the content of an XML File's element which
> > contains a String.
> > This String has to be formatted (a little bit if possible :-) ) with
> > new lines.
> > So that the text:
> >
> > Mister T"NewLineChar"Hannibal Smith"NewLineChar"Looping
> >
> > Where "NewLineChar" should be the expected character
> >
> > After rendering FOP will look like in PDF format to:
> >
> > Mister T
> > Hannibal Smith
> > Looping
> >
> >
> > Is it possible? Or should I find a way to use multiple blocks?
> >
> As mentioned in previous responses you need to add the linefeed 
> characters to the value. However, in addition you need to set the 
> property  linefeed-treatment="preserve" on the enclosing fo:block 
> otherwise the linefeeds in the text will be treated like / converted to 
> spaces and don't generate a line break.
> 
> > Thank you.
> >
> > Miroslav
> >
> >
> Manuel
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
> 

Re: XSL - NewLine

Posted by Manuel Mall <ma...@apache.org>.
On Tuesday 13 February 2007 21:52, Gregan, Miroslav wrote:
> Thanks you for your answers
>
> Actually I afraid I did not ask my question clearly enough.
> The @value which is the content of an XML File's element which
> contains a String.
> This String has to be formatted (a little bit if possible :-) ) with
> new lines.
> So that the text:
>
> Mister T"NewLineChar"Hannibal Smith"NewLineChar"Looping
>
> Where "NewLineChar" should be the expected character
>
> After rendering FOP will look like in PDF format to:
>
> Mister T
> Hannibal Smith
> Looping
>
>
> Is it possible? Or should I find a way to use multiple blocks?
>
As mentioned in previous responses you need to add the linefeed 
characters to the value. However, in addition you need to set the 
property  linefeed-treatment="preserve" on the enclosing fo:block 
otherwise the linefeeds in the text will be treated like / converted to 
spaces and don't generate a line break.

> Thank you.
>
> Miroslav
>
>
Manuel

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: XSL - NewLine

Posted by Abel Braaksma <ab...@xs4all.nl>.
Gregan, Miroslav wrote:
> Thanks you for your answers
>
> Actually I afraid I did not ask my question clearly enough.
> The @value which is the content of an XML File's element which contains
> a String.
> This String has to be formatted (a little bit if possible :-) ) with new
> lines.
> So that the text:
>
> Mister T"NewLineChar"Hannibal Smith"NewLineChar"Looping
>
> Where "NewLineChar" should be the expected character
>
> After rendering FOP will look like in PDF format to:
>
> Mister T
> Hannibal Smith
> Looping
>
>
> Is it possible? Or should I find a way to use multiple blocks?
>   

Your question seemed to be about how to insert line breaks in XML. If 
you want to introduce newlines in the rendered PDF, there is no use 
whatsoever to use line breaks the way we explained to you, because this 
is treated as whitespace and handled accordingly by FOP (or any xsl-fo 
processor for that matter).

Most likely you just want to use <fo:block>...

I do not understand why you want an attribute to contain \r\n as it 
whitespace has no influence on the rendering process. Perhaps you mean 
it the other way around: your source document contains some attribute 
with newlines in it and you want these newlines to be turned into 
<fo:block />. This is then an XSLT question and the answer depends on 
what version you use. In XSLT 2 you can do the following:

<xsl:for-each select="tokenize(@your-attribute, '\n')">
    <fo:block><xsl:value-of select="." />
    ....etc
</xsl:for-each>

Your best bet for this kind of questions is the XSLT list at mulberry 
tech's: http://www.mulberrytech.com/xsl/xsl-list/index.html.

Cheers,
-- Abel Braaksma
   http://xslt.metacarpus.com

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


RE: XSL - NewLine

Posted by "Gregan, Miroslav" <mi...@SIEMENS.COM>.
Thanks you for your answers

Actually I afraid I did not ask my question clearly enough.
The @value which is the content of an XML File's element which contains
a String.
This String has to be formatted (a little bit if possible :-) ) with new
lines.
So that the text:

Mister T"NewLineChar"Hannibal Smith"NewLineChar"Looping

Where "NewLineChar" should be the expected character

After rendering FOP will look like in PDF format to:

Mister T
Hannibal Smith
Looping


Is it possible? Or should I find a way to use multiple blocks?

Thank you.

Miroslav




-----Original Message-----
From: Abel Braaksma [mailto:abel.online@xs4all.nl] 
Sent: Tuesday, February 13, 2007 10:14 AM
To: fop-users@xmlgraphics.apache.org
Subject: Re: XSL - NewLine

Just use:

<xsl:text>&#13;&#10;</xsl:text>
or
<xsl:text>&#xD;&#xA;</xsl:text>

You can also add an entity to your doctype if you tend to use this kind 
of newlines more often:
<!ENTITY newline "&#38;#x0D;&#38;#x0A;" >

and use it as follows:
<xsl:text>&newline;</xsl:text>

which will be rendered as a \r\n by the serializer. Of course, you could

also use an xsl:variable to do the same.

Why do you want a \r *and* a \n? Because if you output XML (which you 
do: XSL-FO) the serializer will make sure that all \r\n will become \n. 
Which means that

<xsl:text>&#xD;&#xA;</xsl:text>

is semantically equivalent with:
<xsl:text>&#xA;</xsl:text>

which means that the newline entity definition will do exactly the same 
when defined thus:
<!ENTITY newline "&#38;#x0A;" >

(not so when you output as text, but that is another story)

If you *have* to have both the \r and the \n in the serialized output (I

have no idea why, I think you don't) then your only bet is XSLT 2.0 
which allows you to put in late-serialization replacements with 
xsl:character-map.

Cheers,
-- Abel Braaksma


Gregan, Miroslav wrote:
> Hello all,
>  
> I need to put manually new line in a pdf document and it has to be for

> the @value field.
> I know, to put a new line I should use a new block, but Is it possible

> to put some kind of "\r\n" string into the value to format it?
>
> <fo:block hyphenate="true" font-size="10pt" font-weight="bold">
>     <xsl:value-of select="@value"/>
> </fo:block>
>
> This XSL document is used to convert an XML document to PDF with 
> either FOP 0.20.5 or 0.93 used embedded in a java 5.0 code.
>  
> Thank you for your help.
>  
> Kind regards,
>  
> Miroslav Gregan
>  
> Siemens PSE-SK KB SK2
> Dubravska cesta 4
> 84104 Bratislava
> Slovakia
>  


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: XSL - NewLine

Posted by Abel Braaksma <ab...@xs4all.nl>.
Just use:

<xsl:text>&#13;&#10;</xsl:text>
or
<xsl:text>&#xD;&#xA;</xsl:text>

You can also add an entity to your doctype if you tend to use this kind 
of newlines more often:
<!ENTITY newline "&#38;#x0D;&#38;#x0A;" >

and use it as follows:
<xsl:text>&newline;</xsl:text>

which will be rendered as a \r\n by the serializer. Of course, you could 
also use an xsl:variable to do the same.

Why do you want a \r *and* a \n? Because if you output XML (which you 
do: XSL-FO) the serializer will make sure that all \r\n will become \n. 
Which means that

<xsl:text>&#xD;&#xA;</xsl:text>

is semantically equivalent with:
<xsl:text>&#xA;</xsl:text>

which means that the newline entity definition will do exactly the same 
when defined thus:
<!ENTITY newline "&#38;#x0A;" >

(not so when you output as text, but that is another story)

If you *have* to have both the \r and the \n in the serialized output (I 
have no idea why, I think you don't) then your only bet is XSLT 2.0 
which allows you to put in late-serialization replacements with 
xsl:character-map.

Cheers,
-- Abel Braaksma


Gregan, Miroslav wrote:
> Hello all,
>  
> I need to put manually new line in a pdf document and it has to be for 
> the @value field.
> I know, to put a new line I should use a new block, but Is it possible 
> to put some kind of "\r\n" string into the value to format it?
>
> <fo:block hyphenate="true" font-size="10pt" font-weight="bold">
>     <xsl:value-of select="@value"/>
> </fo:block>
>
> This XSL document is used to convert an XML document to PDF with 
> either FOP 0.20.5 or 0.93 used embedded in a java 5.0 code.
>  
> Thank you for your help.
>  
> Kind regards,
>  
> Miroslav Gregan
>  
> Siemens PSE-SK KB SK2
> Dubravska cesta 4
> 84104 Bratislava
> Slovakia
>  


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org