[xsl] RE: Seperating Heading from Content

Subject: [xsl] RE: Seperating Heading from Content
From: "Struijk, Toon van der" <aecvanderstruijk@xxxxxxxxx>
Date: Fri, 18 Nov 2011 15:53:03 +0100
Ken,

I've tried to get the <fo:marker> issue to work, but it is still not right.
Maybe you could have a look at the XSL-FO file I have created so far (it is
the complete file, so a lot of it may not be of any interest to you).
Read the sections <fo:static-content flow-name="header"> and <xsl:template
match="h2">. The first one retrieves the marker defined in the <xsl:template
match="h2">.
When I render the PDF the H2 tags are not rendered, but everything else in the
<body> section of the XML file is.


===XSL-FO FILE=========================

<?xml version="1.0" encoding="UTF-8"?>

<!-- XSL voor de A4 patikntenbrochure GGZ NHN -->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:fo="http://www.w3.org/1999/XSL/Format"; version='1.0'>
	<xsl:include href="GGZ-NHN_A4_Styles.xsl"/>

<xsl:output indent="yes"/>
	<xsl:template match="folderA4"> <!-- Refereerd aan de rootnode van de te
importeren XML -->

<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format";>

	<fo:layout-master-set>
		<fo:simple-page-master master-name="title-page" page-width="210mm"
page-height="297mm" margin-left="34.5pt" margin-right="36pt"
margin-top="28.188pt" margin-bottom="58.7pt">
			<fo:region-body margin-right="0mm" region-name="head" />
			<fo:region-after region-name="footer-odd" />
		</fo:simple-page-master>

		<fo:simple-page-master master-name="toc-page" page-width="210mm"
page-height="297mm" margin-left="34.5pt" margin-right="36pt"
margin-top="126pt" margin-bottom="58.7pt">
			<fo:region-body margin-right="0mm" region-name="toc" margin-left="0mm" />
			<fo:region-after region-name="footer-even" />
			<fo:region-end extent="0mm"/>
		</fo:simple-page-master>

		<fo:simple-page-master master-name="odd-page" page-width="210mm"
page-height="297mm" margin-left="34.5pt" margin-right="36pt"
margin-top="126pt" margin-bottom="58.7pt">
			<fo:region-before extent="-35pt" region-name="header"/>
			<fo:region-body margin-right="0mm" margin-left="0mm" />
			<fo:region-after region-name="footer-odd" />
			<fo:region-end extent="0mm"/>
		</fo:simple-page-master>

		<fo:simple-page-master master-name="even-page" page-width="210mm"
page-height="297mm" margin-left="34.5pt" margin-right="36pt"
margin-top="126pt" margin-bottom="58.7pt">
			<fo:region-before extent="-35pt" region-name="header"/>
			<fo:region-body margin-right="0mm" margin-left="0mm" />
			<fo:region-after region-name="footer-even" />
			<fo:region-end extent="0mm"/>
		</fo:simple-page-master>

		<fo:page-sequence-master master-name="Brochure">
			<fo:single-page-master-reference master-reference="title-page" />
			<fo:single-page-master-reference master-reference="toc-page" />
			<fo:repeatable-page-master-alternatives>
				<fo:conditional-page-master-reference master-reference="odd-page"
odd-or-even="odd" />
				<fo:conditional-page-master-reference master-reference="even-page"
odd-or-even="even"  />
			</fo:repeatable-page-master-alternatives>
		</fo:page-sequence-master>
	</fo:layout-master-set>

	<fo:page-sequence master-reference="Brochure"
xsl:use-attribute-sets="font-body-normal" hyphenate="false" language="NL"
widows="2" orphans="2" hyphenation-push-character-count="3"
hyphenation-remain-character-count="3" format="1" initial-page-number="1">
		<fo:flow flow-name="head">
			<fo:block language="nl" country="nl">
				<xsl:apply-templates select="head" />
			</fo:block>
		</fo:flow>

		<fo:flow flow-name="toc">
			<fo:block margin-top="-67.5pt" margin-left="-34.5pt" margin-right="-36pt"
border-width="1.15pt" border-color="black" border-top-style="solid"
border-bottom-style="none" border-left-style="none" border-right-style="none"
>
				<fo:block margin-top="34pt" margin-left="34.5pt" margin-right="36pt"
xsl:use-attribute-sets="font-h2" language="nl" country="nl"
><xsl:text>Inhoudsopgave</xsl:text></fo:block> <!--  space-after="33.5pt" -->
				</fo:block>
			<xsl:apply-templates mode="TOC"/>
		</fo:flow>


		<fo:flow flow-name="xsl-region-body">
			<fo:block margin-top="-67.5pt" margin-left="-34.5pt" margin-right="-36pt"
border-width="1.15pt" border-color="black" border-top-style="solid"
border-bottom-style="none" border-left-style="none" border-right-style="none"
>
				<fo:block margin-top="70pt" margin-left="34.5pt" margin-right="36pt"
language="nl" country="nl"> <!--margin-top="34pt"-->
					<xsl:apply-templates select="body" />
				</fo:block>

			</fo:block>
		</fo:flow>

		<fo:static-content flow-name="header">
			<fo:block margin-top="-50pt" border-width="0.5pt" border-color="black"
border-top-style="solid" border-bottom-style="none" border-left-style="none"
border-right-style="none">
				<fo:retrieve-marker retrieve-class-name="hoofdstuk" />
			</fo:block>
		</fo:static-content>

		<fo:static-content flow-name="footer-odd">
			<fo:block margin-top="14.25pt" border-width="0.5pt" border-color="black"
border-top-style="solid" border-bottom-style="none" border-left-style="none"
border-right-style="none">
				<fo:block margin-top="2.85mm" text-align="outside"
xsl:use-attribute-sets="font-body-bold" >
						<fo:page-number />
					</fo:block>
			</fo:block>
		</fo:static-content>

		<fo:static-content flow-name="footer-even">
			<fo:block margin-top="14.25pt" border-width="0.5pt" border-color="black"
border-top-style="solid" border-bottom-style="none" border-left-style="none"
border-right-style="none">
				<fo:block margin-top="2.85mm" text-align="outside"
xsl:use-attribute-sets="font-body-bold" >
					<fo:page-number />
				</fo:block>
			</fo:block>
		</fo:static-content>
	</fo:page-sequence>
</fo:root>

</xsl:template>

<!-- BEGIN TOC -->

	<xsl:template match="h2" mode="TOC">
		<fo:block xsl:use-attribute-sets="font-h2-toc" margin-left="12pt"
space-before="0pt" space-after="6pt" text-align-last="justify">
			<fo:inline>
				<xsl:value-of select="current()"/>
				<fo:leader xsl:use-attribute-sets="font-toc-dots" leader-pattern="dots"
leader-alignment="reference-area" />
				<fo:page-number-citation xsl:use-attribute-sets="font-h2-toc"
ref-id="{generate-id(current())}"/>
			</fo:inline>
		</fo:block>
		<xsl:apply-templates select="h3" mode="TOC"/>
	</xsl:template>
	<xsl:template match="h3" mode="TOC">
		<fo:block xsl:use-attribute-sets="font-h3-toc" margin-left="25pt"
space-after="6pt" text-align-last="justify">
			<fo:inline>
				<xsl:value-of select="current()"/>
				<fo:leader xsl:use-attribute-sets="font-toc-dots" leader-pattern="dots"/>
				<fo:page-number-citation xsl:use-attribute-sets="font-h2-toc"
ref-id="{generate-id(current())}"/>
			</fo:inline>
		</fo:block>
	</xsl:template>

<!-- EINDE TOC -->


	<xsl:template match="h2">
		<fo:block xsl:use-attribute-sets="font-h2" space-before="-29pt"
space-after="29pt" absolute-position="fixed" top="-29pt"
keep-with-next="always" page-break-before="always" id="{generate-id(.)}" >
			<fo:marker marker-class-name="hoofdstuk">
				<xsl:value-of select="." />
			</fo:marker>
		</fo:block>
	</xsl:template>


<xsl:template match="head">
	<fo:external-graphic src="url(GGZ-NHN_Divisie.svg)" scaling="uniform"
width="210mm" margin-left="-34.5pt" margin-top="-3cm" text-align="left" />
	<fo:block xsl:use-attribute-sets="font-titel" space-before="-19.6pt"
hyphenate="false" line-stacking-strategy="line-height" ><xsl:apply-templates
select="title"/></fo:block>
	<fo:block xsl:use-attribute-sets="font-intro" space-before="29.6pt"
space-after="15pt" hyphenate="false" ><xsl:apply-templates
select="intro"/></fo:block>

	<fo:block xsl:use-attribute-sets="font-body-bold" space-before="19pt"
space-after="15pt" ><xsl:apply-templates select="locatietitle"/></fo:block>
	<fo:block xsl:use-attribute-sets="font-body-normal" space-after="19pt"
><xsl:apply-templates select="locatiebody"/></fo:block>
</xsl:template>

<xsl:template match="locatie">
	<fo:block xsl:use-attribute-sets="font-body-bold" space-before="19pt"
space-after="15pt"><xsl:apply-templates select="locatietitle"/></fo:block>
	<fo:block xsl:use-attribute-sets="font-body-normal" space-after="19pt"
><xsl:apply-templates select="locatiebody"/></fo:block>
</xsl:template>

<xsl:template match="p">
	<fo:block  xsl:use-attribute-sets="font-body-normal" space-before="9pt"
space-after="9pt" > <!--space-after="15pt"-->
		<xsl:apply-templates/>
	</fo:block>
</xsl:template>

<xsl:template match="blockquote">
	<fo:wrapper  xsl:use-attribute-sets="font-body-italic" space-before="9pt"
space-after="9pt" > <!--space-after="15pt"-->
		<xsl:apply-templates/>
	</fo:wrapper>
</xsl:template>

<xsl:template match="i">
	<fo:wrapper xsl:use-attribute-sets="font-body-italic" >
		<xsl:apply-templates/>
	</fo:wrapper>
</xsl:template>

<xsl:template match="ol">
	<fo:list-block xsl:use-attribute-sets="font-body-normal" >
		<xsl:apply-templates/>
	</fo:list-block>
</xsl:template>


<xsl:template match="ul">
	<fo:list-block xsl:use-attribute-sets="font-body-normal" space-before="0pt"
space-after="15pt" >
		<xsl:apply-templates/>
	</fo:list-block>
</xsl:template>

	<xsl:template match="ol/li">
	<fo:list-item>
		<fo:list-item-label>
			<fo:block  line-height="18pt">
				<xsl:number format="1. "/>
			</fo:block>
		</fo:list-item-label>
		<fo:list-item-body >
			<fo:block start-indent="-10pt" end-indent="0"
xsl:use-attribute-sets="font-body-normal">
				<xsl:apply-templates/>
			</fo:block>
		</fo:list-item-body >
	</fo:list-item>
</xsl:template>

	<xsl:template match="ul/li">
		<fo:list-item>
			<fo:list-item-label>
				<fo:block line-height="18pt">- </fo:block>
			</fo:list-item-label>
			<fo:list-item-body >
				<fo:block start-indent="-10pt" end-indent="0"
xsl:use-attribute-sets="font-body-normal">
					<xsl:apply-templates/>
				</fo:block>
			</fo:list-item-body >
		</fo:list-item>
	</xsl:template>


<xsl:template match="strong">
	<fo:wrapper xsl:use-attribute-sets="font-body-bold">
		<xsl:apply-templates/>
	</fo:wrapper>
</xsl:template>

<xsl:template match="br">
	<fo:block>
		<fo:character character=""/>
	</fo:block>
</xsl:template>

<xsl:template match="h3">
	<fo:block xsl:use-attribute-sets="font-h3" keep-with-next="always"
id="{generate-id(.)}">
		<xsl:apply-templates/>
	</fo:block>
</xsl:template>

<xsl:template match="h4">
	<fo:block xsl:use-attribute-sets="font-h4" keep-with-next="always" >
		<xsl:apply-templates/>
	</fo:block>
</xsl:template>

<xsl:template match="img">
  <fo:block space-before="15pt" space-after="15pt">
    <fo:external-graphic src="{@src}" >
      <xsl:if test="@width">
        <xsl:attribute name="width">
          <xsl:choose>
            <xsl:when test="contains(@width, 'px')">
              <xsl:value-of select="@width"/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="concat(@width, 'px')"/>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:attribute>
      </xsl:if>
      <xsl:if test="@height">
        <xsl:attribute name="height">
          <xsl:choose>
            <xsl:when test="contains(@height, 'px')">
              <xsl:value-of select="@height"/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="concat(@height, 'px')"/>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:attribute>
      </xsl:if>
    </fo:external-graphic>
  </fo:block>
</xsl:template>

</xsl:stylesheet>
===============================

If you need morte information, please let me know.




Met vriendelijke groet,

Toon van der Struijk
Art Director

Elektronicaweg 31
2628 XG Delft, Nederland
T +31 (0)15 - 251 37 00
F +31 (0)15 - 251 37 01
M  +31 (0)6 - 1309 0937
E aecvanderstruijk@xxxxxxxxx

Op dit mailbericht is onze disclaimer van kracht.

Current Thread