Skip to content

Instantly share code, notes, and snippets.

/guideline.xsl Secret

Created September 8, 2016 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/8df09b60a99d9c2c0883475d2e010289 to your computer and use it in GitHub Desktop.
Save anonymous/8df09b60a99d9c2c0883475d2e010289 to your computer and use it in GitHub Desktop.
Work in progress performing XSL-FO transformation
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:exsl="http://exslt.org/common"
extension-element-prefixes="exsl"
version="2.0"
xsi:schemaLocation="http://www.w3.org/1999/XSL/Format http://svn.apache.org/repos/asf/xmlgraphics/fop/trunk/fop/src/foschema/fop.xsd">
<xsl:template match="/guideline">
<!--We'll use the EXSLT extensions to be able to map a 'result tree fragment' (the variable) to a node-set-->
<xsl:variable name="summary">
<item>
<label>Number of Children</label>
<col1></col1>
<col2></col2>
<col3>
<xsl:value-of select="count(children/child)"/>
</col3>
</item>
<item>
<label>Percentage of Time with Child<xsl:if test="count(children/child) &gt; 1">ren</xsl:if>
</label>
<col1 unit="%">
<xsl:value-of select="parents/parent[1]/percentOfTime"/>
</col1>
<col2>
<xsl:value-of select="parents/parent[2]/percentOfTime"/>
</col2>
<col3>3</col3>
</item>
</xsl:variable>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"
font-family="Courier" font-size="4mm">
<fo:layout-master-set>
<fo:simple-page-master master-name="portraitLayout"
page-height="279.4mm"
page-width="215.9mm"
margin-top="25.2mm"
margin-bottom="25.2mm"
margin-left="19.45mm"
margin-right="19.45mm">
<fo:region-body auto-restore="true"/>
<fo:region-before extent="1in"/>
<fo:region-after extent="1in"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="portraitLayout">
<!--<fo:static-content flow-name="xsl-region-after">
<fo:block line-height="14pt" font-size="10pt" text-align="end">
page
<fo:page-number/>
</fo:block>
</fo:static-content>-->
<fo:flow flow-name="xsl-region-body" min-width="177mm">
<fo:block>From EXSLT:
<xsl:call-template name="section_body">
<xsl:with-param name="list" select="exsl:node-set($summary)"/>
</xsl:call-template>
</fo:block>
<xsl:call-template name="divider"/>
<xsl:call-template name="section_header">
<xsl:with-param name="section"></xsl:with-param>
<xsl:with-param name="title">Family Court</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="divider"/>
<fo:block>
<fo:table table-layout="fixed" width="177mm"
margin="0" padding="0"
>
<fo:table-column column-width="88.5mm"/>
<fo:table-column column-width="88.5mm"/>
<fo:table-body>
<fo:table-row>
<fo:table-cell>
<fo:table table-layout="fixed" width="88.5mm"
margin="0" padding="0">
<fo:table-column column-width="23mm"/>
<fo:table-column column-width="65.5mm"/>
<fo:table-body>
<fo:table-row>
<fo:table-cell>
<fo:block>CP:</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>Parent A</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:block/>
</fo:table-cell>
<fo:table-cell>
<fo:block>and</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:block>NCP:</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>Parent B</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:table-cell>
<fo:table-cell>
<fo:table table-layout="fixed" width="88.5mm">
<fo:table-column column-width="31mm"/>
<fo:table-column column-width="57.5mm"/>
<fo:table-body>
<fo:table-row>
<fo:table-cell>
<fo:block>WORKSHEET:</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>Sole</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:block>COUNTY:</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>Chittenden</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:block>
<xsl:call-template name="divider"/>
<xsl:call-template name="section_header">
<xsl:with-param name="title">Children</xsl:with-param>
</xsl:call-template>
<!--todo: parse child nodes here-->
<xsl:call-template name="divider"/>
<xsl:call-template name="section_header">
<xsl:with-param name="title">Custody Information</xsl:with-param>
<xsl:with-param name="col1">CP</xsl:with-param>
<xsl:with-param name="col2">NCP</xsl:with-param>
<xsl:with-param name="col3">Total</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="divider"/>
<xsl:call-template name="section_header">
<xsl:with-param name="section">Part I.</xsl:with-param>
<xsl:with-param name="title">Monthly Available</xsl:with-param>
<xsl:with-param name="col1">CP</xsl:with-param>
<xsl:with-param name="col2">NCP</xsl:with-param>
<xsl:with-param name="col3">Combined</xsl:with-param>
</xsl:call-template>
<xsl:call-template name="divider"/>
<fo:table table-layout="fixed" width="100%" margin="0" padding="0"
space-before="13mm" space-after="3mm"
>
<fo:table-column column-width="50%"/>
<fo:table-column column-width="50%"/>
<fo:table-body>
<fo:table-row>
<fo:table-cell>
<fo:block text-align-last="justify">
<xsl:text>Text in col1</xsl:text>
<fo:leader leader-pattern="dots"/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block text-align-last="justify">
<fo:leader leader-pattern="dots"/>
<xsl:text>Text in col2</xsl:text>
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
<xsl:call-template name="divider"/>
<fo:table table-layout="fixed" width="100%" margin="0" padding="0"
space-before="13mm" space-after="3mm"
>
<fo:table-column column-width="50%"/>
<fo:table-column column-width="50%"/>
<fo:table-body>
<fo:table-row>
<fo:table-cell>
<fo:block text-align-last="justify">
<xsl:text>Text in col1</xsl:text>
<fo:leader leader-pattern="dots"/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block text-align-last="justify">
<fo:leader leader-pattern="dots"/>
<xsl:text>Text in col2</xsl:text>
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<!--reusable assets-->
<xsl:template name="divider">
<fo:block>
<fo:leader leader-length="100%" leader-pattern="rule" rule-thickness="0.1mm"/>
</fo:block>
</xsl:template>
<xsl:template name="section_header">
<xsl:param name="section"/>
<xsl:param name="title"/>
<xsl:param name="col1"/>
<xsl:param name="col2"/>
<xsl:param name="col3"/>
<!--Everything in this block will be upper-cased.-->
<fo:block text-transform="uppercase">
<fo:table table-layout="fixed" width="177mm"
margin="0" padding="0">
<fo:table-column column-width="23mm"/>
<fo:table-column column-width="64mm"/>
<fo:table-column column-width="29mm"/>
<fo:table-column column-width="29mm"/>
<fo:table-column column-width="29mm"/>
<fo:table-body>
<fo:table-row>
<fo:table-cell>
<fo:block>
<xsl:value-of select="$section"/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
<xsl:value-of select="$title"/>
</fo:block>
</fo:table-cell>
<fo:table-cell text-align="right">
<fo:block>
<xsl:value-of select="$col1"/>
</fo:block>
</fo:table-cell>
<fo:table-cell text-align="right">
<fo:block>
<xsl:value-of select="$col2"/>
</fo:block>
</fo:table-cell>
<fo:table-cell text-align="right">
<fo:block>
<xsl:value-of select="$col3"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:block>
</xsl:template>
<xsl:template name="section_body">
<xsl:param name="list"/>
<!--Everything in this block will be upper-cased.-->
<fo:block>
<fo:table table-layout="fixed" width="177mm"
margin="0" padding="0">
<fo:table-column column-width="90mm"/>
<fo:table-column column-width="29mm"/>
<fo:table-column column-width="29mm"/>
<fo:table-column column-width="29mm"/>
<fo:table-body>
<xsl:for-each select="$list/item">
<fo:table-row>
<fo:table-cell><!-- padding-before="label[@padding]"-->
<fo:block>
<xsl:value-of select="label"/>
</fo:block>
</fo:table-cell>
<fo:table-cell text-align="left">
<fo:block>
<xsl:value-of select="col1"/>
<xsl:value-of select="col1/@unit"/>
</fo:block>
</fo:table-cell>
<fo:table-cell text-align="right">
<fo:block>
<xsl:value-of select="col2"/>
</fo:block>
</fo:table-cell>
<fo:table-cell text-align="right">
<fo:block>
<xsl:value-of select="col3"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:for-each>
</fo:table-body>
</fo:table>
</fo:block>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment