Re: [xsl] How to integrate XSLT tags with FO tags

Subject: Re: [xsl] How to integrate XSLT tags with FO tags
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Sun, 12 Apr 2009 13:17:43 -0400
At 2009-04-12 16:09 +0000, LiuKui wrote:
I began to study XSL 2 weeks ago, now I don't understand how to integrate XSLT tags with FO tags in a single .xsl file. For example:

<?xml version="1.0" encoding="UTF-8"?>
<?xsl:stylesheet type="text/xsl" href="person.xsl"?>
<person first-name="Kui" last-name="Liu"/>

In order to format the .xml file above, I want to use the following .xsl file:

Your stylesheet is a complete stylesheet (with errors), but it is not creating a complete XSL-FO result.


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3c.org/1999/XSL/Transform"; xmlns:fo="http://www.w3c.org/1999/XSL/Format";>

Note that you are using the wrong namespaces. Change "w3c" to "w3" in the above namespaces.


<xsl:template match="person">
<fo:block border="thick silver ridge">
<xsl:value-of select="@last-name"/>
<xsl:text> </xsl:text>
<xsl:value-of select="@first-name"/>
</fo:block>
</xsl:template>
</xsl:stylesheet>

But it seems that the FOP can not generate valid .pdf file from these two files above,

Correct, because unlike HTML in browsers, you cannot simply throw "tag soup" at an XSL-FO engine and expect blocks to be displayed. You need to have the proper document element <fo:root>, and then you need to specify the page geometry.


For example, here is a stylesheet that creates a more complete XSL-FO result:

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                xmlns:fo="http://www.w3.org/1999/XSL/Format";>

<xsl:template match="/">
<fo:root font-family="Times" font-size="20pt">

  <fo:layout-master-set>
    <fo:simple-page-master master-name="frame"
                        page-width="210mm" page-height="297mm"
                        margin-top="1cm" margin-bottom="1cm"
                        margin-left="1cm" margin-right="1cm">
      <fo:region-body region-name="frame-body"/>
    </fo:simple-page-master>
  </fo:layout-master-set>

  <fo:page-sequence master-reference="frame">
    <fo:flow flow-name="frame-body">
      <xsl:apply-templates/>
    </fo:flow>
  </fo:page-sequence>
</fo:root>
</xsl:template>

<xsl:template match="person">
<fo:block border="thick silver ridge">
<xsl:value-of select="@last-name"/>
<xsl:text> </xsl:text>
<xsl:value-of select="@first-name"/>
</fo:block>
</xsl:template>
</xsl:stylesheet>

and <fo:foot> tag doesn't coexist with <xsl:stylesheet> tag.

There is no element <fo:foot> in the XSL-FO vocabulary. Perhaps you meant to type <fo:root>.


What's more, I find that Windows IE fails to recognise .fo file, which makes me a little confused.

Internet Explorer is an HTML browser and not an XSL-FO engine. It does not recognize the XSL-FO vocabulary. It only recognizes the HTML vocabulary.


Could anyone be so kind as to explain these problems to me?

I hope this helps. I suggest you find some instruction somewhere in a book or course in order to learn foundation basics.


. . . . . . . . . . . . Ken

p.s. for those in North America, I'm teaching the foundations of XSL-FO and an overview of every formatting object in the upcoming 3-day hands-on training in the Los Angeles area in June 2009; it is preceded by 5-day hands-on training for XSLT and XQuery the week before.


-- XSLT/XSL-FO/XQuery training in Los Angeles (New dates!) 2009-06-08 Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video Video lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18 Video overview: http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18 G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal

Current Thread