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 Raphael Parree <rp...@gmail.com> on 2007/10/06 18:40:59 UTC

unparsed-text

Hi,

 

I am in the midst of upgrading to XSLT 2.0. One of the reasons moving is to
be able to use the XSLT function unparsed-text.

 

I am using it like:

<fo:page-sequence master-reference="somref

  <fo:flow flow-name="xsl-region-body">

    <fo:block>

      <xsl:value-of select="unparsed-text('about.fo'),'utf-8')" 

                         disable-output-escaping="yes"/>

    </fo:block>

  </fo:flow>

</fo:page-sequence>

 

The about.fo is an fo file.

 

The resulting PDF however has a page full of FO instructions (the literal
contents of the about.fo file) not rendered by the FOP engine. When I run
with an XSLT engine (Saxon in oXygen), the resulting fo file looks ok (with
the about.fo nicely in it)

 

I am using my transformer like: transformer.transform(xmlSource, new
SAXResult(fop.getDefaultHandler()));

 

I am using Saxon8, the fop version I am not 100% (my build id is Build-Id in
the manifest is: 20061120-085325-CET, so I probably have a version from end
of last year.)

 

Any clues?

 

Tx.,

 

Raphael


Re: unparsed-text

Posted by Abel Braaksma <ab...@xs4all.nl>.
Raphael Parree wrote:
> ...i did not change the use of unparsed-text {blush} and replaced it with
> document as per you suggestion in your original email . My Sunday has a much
> brighter start, as it works as expected now. Thanks for you assistance much
> appreciated!
>
> Have a good one,

I'll do that ;)
Great that is works now!

Cheers,
-- Abel Braaksma

PS: one good tip: sign up with the xsl list 
http://www.mulberrytech.com/xsl/xsl-list/subscribe-unsubscribe.html, 
even if you don't ask questions, just by reading along with the posts 
you will learn a lot about XSLT 2.0 and its (im)possibilities, 
strategies and best practices.

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


RE: unparsed-text

Posted by Raphael Parree <rp...@gmail.com>.
Abel,

...i did not change the use of unparsed-text {blush} and replaced it with
document as per you suggestion in your original email . My Sunday has a much
brighter start, as it works as expected now. Thanks for you assistance much
appreciated!

Have a good one,

Raphael


-----Original Message-----
From: Abel Braaksma [mailto:abel.online@xs4all.nl] 
Sent: 06 October 2007 23:43
To: fop-users@xmlgraphics.apache.org
Subject: Re: unparsed-text

Hmm, this is the moment that in a comic book all kinds of question marks 
in balloons are floating above my head....

I build most of my FO documents joining and knitting together snippets 
etc. It doesn't (shouldn't) matter the least whether you have an XML 
declaration or not. The xml namespace *is* important though if it 
incorrect it will not be recognized and your FO processor will spawn errors.

But I'm curious about the way it is used or what is happening... Do you 
really have an XSLT file like the following:

<xsl:stylesheet
    xmlns:fo="http://www.w3.org/1999/XSL/Format"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="2.0">
   
    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="/">
        <fo:root writing-mode="lr-tb" hyphenate="false" 
text-align="start" role="xhtml:html">
            <fo:layout-master-set>
                <fo:simple-page-master page-width="auto" 
page-height="auto" master-name="all-pages">
                        .... your thing ...
                </
            </
       
            <fo:page-sequence master-reference="all-pages">
            .... etc....
                <fo:flow flow-name="xsl-region-body">
                    <fo:block>
                        <xsl:copy-of 
select="document('my-other-fo-document.fo')" />
                    </
                </
             </
          </
    </xsl:template>

    <xsl:template match="otherthings" >
       ... other things here ...
    </

</xsl:stylesheet>


Or, in other words, where does your stylesheet go different than this? 
If you view the intermediate output, i.e., before it gets to the FO 
processor (FOP), how does it look? Do the problem-elements look like 
&lt;fo:block&gt; or do you see them as < fo:block>? And I mean: in a 
text editor of course, don't view it in a browser or somewhere else 
where the XML gets interpreted.

But I have the feeling we're on the wrong track here, because what it 
seems that you are describing seems as being impossible. You have to 
pull quite some tricks to read a genuine XML document using the 
document() function and output it as stringized XML (with stringized I 
mean <node> becomes &lt;node&gt;).

Can you post a (minimal) example of a source document, the main XSLT you 
are using, the about.fo you are including? Can you also try to run it 
with Saxon and then run it with FOP.bat on the commandline, see if the 
effect is equal?

Sorry if I can't (yet) be of more help.

Cheers,
-- Abel Braaksma

Raphael Parree wrote:
> Abel,
>
> Even the snippet from below echoes into the PDF as listed:
>
> about.fo:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <fo:block  id="one" xmlns:fo="http://www.w3.org/1999/XSL/Format">
>   <fo:block font-weight="bold">test</fo:block>
> </fo:block>
>   
> I have tried with and without xml declaration, and with/without the
> namespace declaration.
>
>
>
>   


---------------------------------------------------------------------
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: unparsed-text

Posted by Abel Braaksma <ab...@xs4all.nl>.
Hmm, this is the moment that in a comic book all kinds of question marks 
in balloons are floating above my head....

I build most of my FO documents joining and knitting together snippets 
etc. It doesn't (shouldn't) matter the least whether you have an XML 
declaration or not. The xml namespace *is* important though if it 
incorrect it will not be recognized and your FO processor will spawn errors.

But I'm curious about the way it is used or what is happening... Do you 
really have an XSLT file like the following:

<xsl:stylesheet
    xmlns:fo="http://www.w3.org/1999/XSL/Format"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="2.0">
   
    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="/">
        <fo:root writing-mode="lr-tb" hyphenate="false" 
text-align="start" role="xhtml:html">
            <fo:layout-master-set>
                <fo:simple-page-master page-width="auto" 
page-height="auto" master-name="all-pages">
                        .... your thing ...
                </
            </
       
            <fo:page-sequence master-reference="all-pages">
            .... etc....
                <fo:flow flow-name="xsl-region-body">
                    <fo:block>
                        <xsl:copy-of 
select="document('my-other-fo-document.fo')" />
                    </
                </
             </
          </
    </xsl:template>

    <xsl:template match="otherthings" >
       ... other things here ...
    </

</xsl:stylesheet>


Or, in other words, where does your stylesheet go different than this? 
If you view the intermediate output, i.e., before it gets to the FO 
processor (FOP), how does it look? Do the problem-elements look like 
&lt;fo:block&gt; or do you see them as < fo:block>? And I mean: in a 
text editor of course, don't view it in a browser or somewhere else 
where the XML gets interpreted.

But I have the feeling we're on the wrong track here, because what it 
seems that you are describing seems as being impossible. You have to 
pull quite some tricks to read a genuine XML document using the 
document() function and output it as stringized XML (with stringized I 
mean <node> becomes &lt;node&gt;).

Can you post a (minimal) example of a source document, the main XSLT you 
are using, the about.fo you are including? Can you also try to run it 
with Saxon and then run it with FOP.bat on the commandline, see if the 
effect is equal?

Sorry if I can't (yet) be of more help.

Cheers,
-- Abel Braaksma

Raphael Parree wrote:
> Abel,
>
> Even the snippet from below echoes into the PDF as listed:
>
> about.fo:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <fo:block  id="one" xmlns:fo="http://www.w3.org/1999/XSL/Format">
>   <fo:block font-weight="bold">test</fo:block>
> </fo:block>
>   
> I have tried with and without xml declaration, and with/without the
> namespace declaration.
>
>
>
>   


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


RE: unparsed-text

Posted by Raphael Parree <rp...@gmail.com>.
Abel,

Even the snippet from below echoes into the PDF as listed:

about.fo:

<?xml version="1.0" encoding="UTF-8"?>
<fo:block  id="one" xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <fo:block font-weight="bold">test</fo:block>
</fo:block>
  
I have tried with and without xml declaration, and with/without the
namespace declaration.



-----Original Message-----
From: Abel Braaksma [mailto:abel.online@xs4all.nl] 
Sent: 06 October 2007 23:16
To: fop-users@xmlgraphics.apache.org
Subject: Re: unparsed-text

Raphael Parree wrote:
> Abel,
>
> Thanks for you reply. Indeed there are many other reasons why I am moving
to
> XSLT2.0...
>
> I was thinking along the same lines as you...I also came to the conclusion
> that the receiving SAXResult cannot parse the text I added. Using copy-of
> escapes my fo file, so it unfortunately comes out the same way.

Very weird, to say the least. Any FO file is an XML file. The document() 
function can only handle XML documents. Using xsl:copy-of will copy 
exactly what is input. Can you give a snippet of how this about.fo file 
looks like? If it isn't XML the document() function will choke, but if 
it is XML and it contains, say, some CDATA element with content that 
looks like XML, than it is stringized XML, which cannot 
(straightforwardly) be interpreted as XML.

To find out, simply paste a part (or whole) of your about.fo file here 
and we'll have a look

>  Perhaps the
> xsl:character-map might solve this, I however do not see yet how I would
use
> that in conjunction with the copy-of...something to look into. What
> obviously works is to save the result of the transformation as text (to a
> StreamResult), and then use a SAXParser to parse the whole thing again to
> FOP's SAX handler.
>   

That wouldn't be the 'XML' or 'XSLT' way to do things and it will become 
awkward in the long run and with maintenance. Just paste your whole 
about.fo here and we'll see what can be done.

Cheers,
-- Abel Braaksma


---------------------------------------------------------------------
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: unparsed-text

Posted by Abel Braaksma <ab...@xs4all.nl>.
Raphael Parree wrote:
> Abel,
>
> Thanks for you reply. Indeed there are many other reasons why I am moving to
> XSLT2.0...
>
> I was thinking along the same lines as you...I also came to the conclusion
> that the receiving SAXResult cannot parse the text I added. Using copy-of
> escapes my fo file, so it unfortunately comes out the same way.

Very weird, to say the least. Any FO file is an XML file. The document() 
function can only handle XML documents. Using xsl:copy-of will copy 
exactly what is input. Can you give a snippet of how this about.fo file 
looks like? If it isn't XML the document() function will choke, but if 
it is XML and it contains, say, some CDATA element with content that 
looks like XML, than it is stringized XML, which cannot 
(straightforwardly) be interpreted as XML.

To find out, simply paste a part (or whole) of your about.fo file here 
and we'll have a look

>  Perhaps the
> xsl:character-map might solve this, I however do not see yet how I would use
> that in conjunction with the copy-of...something to look into. What
> obviously works is to save the result of the transformation as text (to a
> StreamResult), and then use a SAXParser to parse the whole thing again to
> FOP's SAX handler.
>   

That wouldn't be the 'XML' or 'XSLT' way to do things and it will become 
awkward in the long run and with maintenance. Just paste your whole 
about.fo here and we'll see what can be done.

Cheers,
-- Abel Braaksma


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


RE: unparsed-text

Posted by Raphael Parree <rp...@gmail.com>.
Abel,

Thanks for you reply. Indeed there are many other reasons why I am moving to
XSLT2.0...

I was thinking along the same lines as you...I also came to the conclusion
that the receiving SAXResult cannot parse the text I added. Using copy-of
escapes my fo file, so it unfortunately comes out the same way. Perhaps the
xsl:character-map might solve this, I however do not see yet how I would use
that in conjunction with the copy-of...something to look into. What
obviously works is to save the result of the transformation as text (to a
StreamResult), and then use a SAXParser to parse the whole thing again to
FOP's SAX handler.

Again, thanks...

Raphael
 

-----Original Message-----
From: Abel Braaksma [mailto:abel.online@xs4all.nl] 
Sent: 06 October 2007 20:12
To: fop-users@xmlgraphics.apache.org
Subject: Re: unparsed-text

Hi Raphael,

There are many good reasons to move to XSLT 2.0, and one of them could 
very well be to use unparsed-text. But in your case, you don't want 
unparsed text, you want parsed text (that is, you want the content of 
the about.fo file to be interpreted as a literal result element, or you 
may want to process it further). To doe that, you should change the 
below xsl:value-of code (which takes the *value* of a node, which is a 
string) to an xsl:copy-of instruction (which copies the content of the 
select statement to the output without modification, which is what you 
are after).

In lieu of this: using disable-output-escaping is strongly discouraged 
and in general not a good idea. Processors are not required to support 
it and even if they do, the output is not guaranteed to be the same 
across processors, even worse, the the d-o-e instruction may be ignored 
if the processors thinks that is better (i.e., to create a valid 
outputstream it may think it is wise to ignore the d-o-e instruction).

Since you are using the fabulous and widely extended XSLT 2.0, if you 
ever feel the need to go beyond its output encoding capabilities, use 
the xsl:character-map declaration, which gives you a much better control 
over the output than d-o-e ever would. Besides, it is very well defined 
and will guarantee the same output between processors.

Back to your problem. Simply replace the xsl:value-of line as follows 
and all should work:

<xsl:copy-of select="document('about.fo')" />

If you have questions about XSL in general (not specific to FOP) you may 
find the XSL list on Mulberry Technologies an excellent resource. It is 
well maintained and one of its chief posters is the creator of XSLT 2.0 
himself: http://www.mulberrytech.com/xsl/xsl-list/

HTH,
Cheers,
Abel

PS: hopefully someone else will follow-up on the configuration problem 
with FOP to get it to use the transformer from Saxon. I should know 
how-to, but it's too long ago... ;)


Raphael Parree wrote:
>
> Hi,
>
> I am in the midst of upgrading to XSLT 2.0. One of the reasons moving 
> is to be able to use the XSLT function unparsed-text.
>
> I am using it like:
>
> <fo:page-sequence master-reference="somref
>
> <fo:flow flow-name="xsl-region-body">
>
> <fo:block>
>
> <xsl:value-of select="unparsed-text('about.fo'),'utf-8')"
>
> disable-output-escaping="yes"/>
>
> </fo:block>
>
> </fo:flow>
>
> </fo:page-sequence>
>
> The about.fo is an fo file.
>
> The resulting PDF however has a page full of FO instructions (the 
> literal contents of the about.fo file) not rendered by the FOP engine. 
> When I run with an XSLT engine (Saxon in oXygen), the resulting fo 
> file looks ok (with the about.fo nicely in it)
>
> I am using my transformer like: transformer.transform(xmlSource, new 
> SAXResult(fop.getDefaultHandler()));
>
> I am using Saxon8, the fop version I am not 100% (my build id is 
> Build-Id in the manifest is: 20061120-085325-CET, so I probably have a 
> version from end of last year.)
>
> Any clues?
>
> Tx.,
>
> Raphael
>


---------------------------------------------------------------------
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: unparsed-text

Posted by Abel Braaksma <ab...@xs4all.nl>.
Hi Raphael,

There are many good reasons to move to XSLT 2.0, and one of them could 
very well be to use unparsed-text. But in your case, you don't want 
unparsed text, you want parsed text (that is, you want the content of 
the about.fo file to be interpreted as a literal result element, or you 
may want to process it further). To doe that, you should change the 
below xsl:value-of code (which takes the *value* of a node, which is a 
string) to an xsl:copy-of instruction (which copies the content of the 
select statement to the output without modification, which is what you 
are after).

In lieu of this: using disable-output-escaping is strongly discouraged 
and in general not a good idea. Processors are not required to support 
it and even if they do, the output is not guaranteed to be the same 
across processors, even worse, the the d-o-e instruction may be ignored 
if the processors thinks that is better (i.e., to create a valid 
outputstream it may think it is wise to ignore the d-o-e instruction).

Since you are using the fabulous and widely extended XSLT 2.0, if you 
ever feel the need to go beyond its output encoding capabilities, use 
the xsl:character-map declaration, which gives you a much better control 
over the output than d-o-e ever would. Besides, it is very well defined 
and will guarantee the same output between processors.

Back to your problem. Simply replace the xsl:value-of line as follows 
and all should work:

<xsl:copy-of select="document('about.fo')" />

If you have questions about XSL in general (not specific to FOP) you may 
find the XSL list on Mulberry Technologies an excellent resource. It is 
well maintained and one of its chief posters is the creator of XSLT 2.0 
himself: http://www.mulberrytech.com/xsl/xsl-list/

HTH,
Cheers,
Abel

PS: hopefully someone else will follow-up on the configuration problem 
with FOP to get it to use the transformer from Saxon. I should know 
how-to, but it's too long ago... ;)


Raphael Parree wrote:
>
> Hi,
>
> I am in the midst of upgrading to XSLT 2.0. One of the reasons moving 
> is to be able to use the XSLT function unparsed-text.
>
> I am using it like:
>
> <fo:page-sequence master-reference="somref
>
> <fo:flow flow-name="xsl-region-body">
>
> <fo:block>
>
> <xsl:value-of select="unparsed-text('about.fo'),'utf-8')"
>
> disable-output-escaping="yes"/>
>
> </fo:block>
>
> </fo:flow>
>
> </fo:page-sequence>
>
> The about.fo is an fo file.
>
> The resulting PDF however has a page full of FO instructions (the 
> literal contents of the about.fo file) not rendered by the FOP engine. 
> When I run with an XSLT engine (Saxon in oXygen), the resulting fo 
> file looks ok (with the about.fo nicely in it)
>
> I am using my transformer like: transformer.transform(xmlSource, new 
> SAXResult(fop.getDefaultHandler()));
>
> I am using Saxon8, the fop version I am not 100% (my build id is 
> Build-Id in the manifest is: 20061120-085325-CET, so I probably have a 
> version from end of last year…)
>
> Any clues?
>
> Tx.,
>
> Raphael
>


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