XSL-FO List

Here should go questions about transforming XML with XSLT and FOP.
ytesemma
Posts: 1
Joined: Fri May 21, 2010 4:24 pm

XSL-FO List

Post by ytesemma »

I am having problem creating a “List, internal link, external link, subscript and supscript” templates for my XSL-FO file to render my xml file to PDF. The xml documents are tagged this way.
For List

<list type=”bulleted”>
<item>Some Text</item>
</list>

For External Link (<extlink fileref="http://test.org">Text</extlink>) and

For Internal Links (<link idref="appB">appendix B</link>)

For subscripts and superscripts (<supscrpt></supscrpt>) and (<subscrpt></subscript>)

The xsl-fo file that I have created looks like this,

<xsl:template match="list">
<xsl:if test="@type='bulleted'">
<fo:list-block provisional-distance-between-starts="18pt"
provisional-label-separation="3pt">
<fo:list-item-label end-indent="label-end()">
<fo:block>&#x2022;</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()">
<fo:block>
<xsl:apply-templates/>
</fo:block>
</fo:list-item-body>
</fo:list-block>
</xsl:if-->
</xsl:template>

<xsl:template match="link">
<fo:basic-link role="internal link" color="blue" text-decoration="underline">
<xsl:attribute name="internal-destination">
<xsl:value-of select="@idref"/>
</xsl:attribute>
<xsl:apply-templates/>
</fo:basic-link>
</xsl:template>

<xsl:template match="extlink">
<fo:basic-link show-destination="new" role="external link" color="blue"
text-decoration="underline">
<xsl:attribute name="external-destination">
<xsl:value-of select="@fileref"/>
</xsl:attribute>
</fo:basic-link>
</xsl:template>

<xsl:template match="supscrpt">
<fo:inline font-size="smaller" baseline-shift="super">
<xsl:apply-templates/>
</fo:inline>
</xsl:template>

<xsl:template match="subscrpt">
<xsl:if test="subscrpt">
<fo:inline font-size="5pt" baseline-shift="sub">
<xsl:apply-templates/>
</fo:inline>
</xsl:if>
</xsl:template>

Please help
alex_jitianu
Posts: 1008
Joined: Wed Nov 16, 2005 11:11 am

Re: XSL-FO List

Post by alex_jitianu »

Hello,

I've attached a modified version of your stylesheet in which all of your requirements are working.

XML sample:

Code: Select all

<root>
<list type="bulleted">
<item id="appB">An anchor</item>
<item>Another item</item>
<item>Third item</item>
</list>

<link idref="appB">Link to the first item.</link>
<extlink fileref="www.google.com">External
link.</extlink> Text<supscrpt>superscript</supscrpt>text<subscrpt>subscript</subscrpt>text
</root>


XSL:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
exclude-result-prefixes="xs fo" version="2.0">

<xsl:template match="/">
<fo:root>
<fo:layout-master-set>
<fo:simple-page-master master-name="all-pages">
<fo:region-body region-name="xsl-region-body" margin="0.7in" column-gap="0.25in"/>
<fo:region-before region-name="xsl-region-before" extent="0.7in"
display-align="after"/>
<fo:region-after region-name="xsl-region-after" extent="0.7in"
display-align="before"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="all-pages">
<fo:flow flow-name="xsl-region-body">
<fo:block>
<xsl:apply-templates/>
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>

</xsl:template>

<xsl:template match="list">
<xsl:if test="@type='bulleted'">
<!-- Create a list -->
<fo:list-block provisional-distance-between-starts="18pt"
provisional-label-separation="3pt">
<!-- For each item, the match='item' template will generate an entry-->
<xsl:apply-templates/>
</fo:list-block>
</xsl:if>
</xsl:template>

<xsl:template match="item">
<fo:list-item>
<fo:list-item-label end-indent="label-end()">
<fo:block>&#x2022;</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()">
<xsl:element name="fo:block">
<!-- If an ID exists, create an anchor by specifying an 'id' attribute -->
<xsl:if test="exists(@id)">
<xsl:attribute name="id" select="@id"/>
</xsl:if>
<xsl:apply-templates/>
</xsl:element>
</fo:list-item-body>
</fo:list-item>

<xsl:apply-templates/>
</xsl:template>

<xsl:template match="link">
<fo:basic-link role="internal link" color="blue" text-decoration="underline">
<xsl:attribute name="internal-destination">
<xsl:value-of select="@idref"/>
</xsl:attribute>
<xsl:apply-templates/>
</fo:basic-link>
</xsl:template>

<xsl:template match="extlink">
<fo:basic-link show-destination="new" role="external link" color="blue"
text-decoration="underline">
<xsl:attribute name="external-destination">
<xsl:value-of select="@fileref"/>
</xsl:attribute>
<xsl:apply-templates/>
</fo:basic-link>
</xsl:template>

<xsl:template match="supscrpt">
<fo:inline font-size="smaller" baseline-shift="super">
<xsl:apply-templates/>
</fo:inline>
</xsl:template>

<xsl:template match="subscrpt">
<fo:inline font-size="5pt" baseline-shift="sub">
<xsl:apply-templates/>
</fo:inline>
</xsl:template>
</xsl:stylesheet>
A FO tutorial can be found at http://www.renderx.com/files/XSLFormatt ... torial.pdf. Also a good XSLT tutorial is available at http://www.zvon.org/xxl/XSLTutorial/Output/index.html.

Regards,
Alex
--
Alex Jitianu
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Post Reply