Created
June 9, 2011 11:43
-
-
Save theresajayne/1016569 to your computer and use it in GitHub Desktop.
sample template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE xsl:stylesheet | |
[ | |
<!ENTITY nbsp " "> | |
<!ENTITY bull "•"> | |
<!ENTITY tab "	"> | |
<!ENTITY oquote "“"> | |
<!ENTITY cquote "”"> | |
]> | |
<xsl:stylesheet version="1.1" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:fo="http://www.w3.org/1999/XSL/Format" | |
xmlns:svg="http://www.w3.org/2000/svg" | |
xmlns:date="http://exslt.org/dates-and-times" | |
xmlns:fox="http://xml.apache.org/fop/extensions" | |
exclude-result-prefixes="fo"> | |
<xsl:output method="xml" version="1.0" omit-xml-declaration="no" indent="yes"/> | |
<!-- Color Definitions for Template --> | |
<xsl:variable name="grey">cmyk(11%,1%,0%,64%)</xsl:variable> | |
<xsl:variable name="lightgrey">cmyk(4%,0%,0%,23%)</xsl:variable> | |
<xsl:variable name="gold">cmyk(0%,1%,47%,30%)</xsl:variable> | |
<xsl:variable name="white">cmyk(0%,0%,0%,0%)</xsl:variable> | |
<xsl:variable name="areaborder">cmyk(19%,13%,18%,0%)</xsl:variable> | |
<!-- <xsl:variable name="bullet-columns">1</xsl:variable> --> | |
<xsl:variable name="bordercolor" select="$gold"/> | |
<xsl:variable name="image-border-color" select="$gold"/> | |
<xsl:variable name="image-border-style">solid</xsl:variable> | |
<!-- Bleed setting if this is for web only Bleed needs to be set to 0 --> | |
<xsl:variable name="bleed">3</xsl:variable> | |
<!-- Style definitions for use in template | |
They consist of the following that are available in the system | |
2ColumnBoxedBulletList, 3 Column Price Table, Bold, Bold and Italics, Boxed Bullet List, BoxedBulletListColumn1, | |
BoxedBulletListColumn2, Bullet List, Bullet List Level 2, Definition List, Free Format, Full Span Bullet List, | |
Indented, Introduction, Italics, Main Heading, Normal, Numbered List, Price Table, Quotation, Sub Heading 1, Sub Heading 2, | |
Sub Heading 3, Table | |
--> | |
<xsl:attribute-set name="MainHeading"> | |
<xsl:attribute name="font-family">TFArrow</xsl:attribute> | |
<xsl:attribute name="font-weight">medium</xsl:attribute> | |
<xsl:attribute name="font-style">normal</xsl:attribute> | |
<xsl:attribute name="font-size">20pt</xsl:attribute> | |
<xsl:attribute name="text-align">left</xsl:attribute> | |
<xsl:attribute name="color"> | |
<xsl:value-of select="$grey"/> | |
</xsl:attribute> | |
</xsl:attribute-set> | |
<xsl:attribute-set name="Heading"> | |
<xsl:attribute name="letter-spacing">2pt</xsl:attribute> | |
<xsl:attribute name="font-family">TFArrow</xsl:attribute> | |
<xsl:attribute name="font-weight">medium</xsl:attribute> | |
<xsl:attribute name="font-style">normal</xsl:attribute> | |
<xsl:attribute name="font-size">19pt</xsl:attribute> | |
<xsl:attribute name="text-align">right</xsl:attribute> | |
<xsl:attribute name="color"> | |
<xsl:value-of select="$lightgrey"/> | |
</xsl:attribute> | |
</xsl:attribute-set> | |
<xsl:attribute-set name="SubHeading1"> | |
<xsl:attribute name="font-family">Frutiger</xsl:attribute> | |
<xsl:attribute name="font-weight">light</xsl:attribute> | |
<xsl:attribute name="font-style">normal</xsl:attribute> | |
<xsl:attribute name="font-size">18pt</xsl:attribute> | |
<xsl:attribute name="text-align">left</xsl:attribute> | |
<xsl:attribute name="color"> | |
<xsl:value-of select="$gold"/> | |
</xsl:attribute> | |
</xsl:attribute-set> | |
<xsl:attribute-set name="Default"> | |
<xsl:attribute name="font-family">Frutiger</xsl:attribute> | |
<xsl:attribute name="font-weight">light</xsl:attribute> | |
<xsl:attribute name="font-style">normal</xsl:attribute> | |
<xsl:attribute name="font-size">11pt</xsl:attribute> | |
<xsl:attribute name="line-height">14pt</xsl:attribute> | |
<xsl:attribute name="text-align">left</xsl:attribute> | |
<xsl:attribute name="color"> | |
<xsl:value-of select="$grey"/> | |
</xsl:attribute> | |
</xsl:attribute-set> | |
<xsl:attribute-set name="BulletList"> | |
<xsl:attribute name="font-family">Frutiger</xsl:attribute> | |
<xsl:attribute name="font-weight">light</xsl:attribute> | |
<xsl:attribute name="font-style">normal</xsl:attribute> | |
<xsl:attribute name="font-size">11pt</xsl:attribute> | |
<xsl:attribute name="line-height">14pt</xsl:attribute> | |
<xsl:attribute name="text-align">left</xsl:attribute> | |
<xsl:attribute name="color"> | |
<xsl:value-of select="$grey"/> | |
</xsl:attribute> | |
</xsl:attribute-set> | |
<!-- Entry point for the document --> | |
<xsl:template match="*[name() = 'html'] | *[name() = 'HTML']"> | |
<xsl:processing-instruction name="xep-pdf-crop-offset">24pt</xsl:processing-instruction> | |
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:svg="http://www.w3.org/2000/svg"> | |
<fo:layout-master-set> | |
<fo:simple-page-master master-name="a4window" page-height="{$bleed + 297 + $bleed}mm" page-width="{$bleed + 210 + $bleed}mm" margin-top="0cm" margin-bottom="0cm" margin-left="0cm" margin-right="0cm" column-count="2" column-gap="5mm"> | |
<fo:region-before region-name="xsl-region-before" extent="{$bleed + 49}mm"/> | |
<fo:region-body region-name="xsl-region-body" margin-top="{$bleed + 246.75}mm" margin-left="{$bleed +10}mm" margin-right="{10 + $bleed}mm" margin-bottom="0mm" column-count="2" column-gap="4mm"/> | |
<fo:region-after region-name="xsl-region-after" extent="{248 + $bleed}mm" margin-left="{$bleed +10}mm" margin-right="{10 + $bleed}mm"/> | |
</fo:simple-page-master> | |
</fo:layout-master-set> | |
<!-- start the document --> | |
<xsl:call-template name="doWindow"/> | |
</fo:root> | |
</xsl:template> | |
<!-- Sub Templates for specific Definition --> | |
<xsl:template name="doWindow" match="/body"> | |
<!-- ok now to get the reference and pull the master xml document for processing --> | |
<xsl:variable name="raw_property_ref" select="descendant-or-self::*[@id='propertyDetailRef']" /> | |
<xsl:variable name="property_ref" select="substring-after($raw_property_ref,'Ref: ')"/> | |
<!-- we should have the ref now, - lets get the xml document and knowing it is valid xml we can just include it as a document --> | |
<xsl:variable name="source" select="document('http://example.com/xml/properties.xml')"/> | |
<!-- we should have the document now, so lets pull the record for the selected property--> | |
<xsl:variable name="property" select ="$source/agency/branches/branch/properties/*[property_reference=$property_ref]"/> | |
<!-- ok this is the header --> | |
<fo:page-sequence master-reference="a4window"> | |
<fo:static-content flow-name="xsl-region-before"> | |
<fo:block-container background-color="{$grey}" width="{$bleed + 210 + $bleed}" height="{$bleed + 49}mm" position="absolute" top="0" left="0"> | |
<fo:block text-align="right" > </fo:block> | |
</fo:block-container> | |
<fo:block-container top="{$bleed + 10}mm" left="{$bleed + 10}mm" width="73.3mm" height="23.2mm" position="absolute"> | |
<xsl:call-template name="logo"> | |
<xsl:with-param name="width">73.3</xsl:with-param> | |
<xsl:with-param name="height">23.2</xsl:with-param> | |
</xsl:call-template> | |
</fo:block-container> | |
<fo:block-container top="{$bleed+10+20}mm" left="{$bleed + 10 + 73.3}mm" width="115mm" height="8.2mm" position="absolute"> | |
<fo:block xsl:use-attribute-sets="Heading"> | |
<xsl:text>The Surrey Hills Specialists</xsl:text> | |
</fo:block> | |
</fo:block-container> | |
</fo:static-content> | |
<fo:static-content flow-name="xsl-region-after"> | |
<xsl:variable name="title" select="$property/advert_heading/text()"/> | |
<xsl:variable name="price" select="$property/price_text"/> | |
<fo:block-container width="190mm" height="108mm" top="4mm" left="{$bleed+10.073}mm" position="absolute" block-align="center" text-align="center"> | |
<fo:block> | |
<xsl:call-template name="crop-scale-image"> | |
<xsl:with-param name="content-width">189</xsl:with-param> | |
<xsl:with-param name="content-height">107</xsl:with-param> | |
<xsl:with-param name="imgurl"> | |
<xsl:value-of select="$property/pictures/picture[1]/filename/text()"/> | |
</xsl:with-param> | |
</xsl:call-template> | |
</fo:block> | |
</fo:block-container> | |
<fo:block-container width="61mm" height="50.5mm" top="114.75mm" left="{$bleed+10.073}mm" position="absolute" block-align="center" text-align="center"> | |
<fo:block> | |
<xsl:call-template name="crop-scale-image"> | |
<xsl:with-param name="content-width">61</xsl:with-param> | |
<xsl:with-param name="content-height">50</xsl:with-param> | |
<xsl:with-param name="imgurl"> | |
<xsl:value-of select="$property/pictures/picture[2]/filename/text()"/> | |
</xsl:with-param> | |
</xsl:call-template> | |
</fo:block> | |
</fo:block-container> | |
<fo:block-container width="61mm" height="50.5mm" top="114.75mm" left="{$bleed + 74.5}mm" position="absolute" block-align="center" text-align="center"> | |
<fo:block> | |
<xsl:call-template name="crop-scale-image"> | |
<xsl:with-param name="content-width">61</xsl:with-param> | |
<xsl:with-param name="content-height">50</xsl:with-param> | |
<xsl:with-param name="imgurl"> | |
<xsl:value-of select="$property/pictures/picture[3]/filename/text()"/> | |
</xsl:with-param> | |
</xsl:call-template> | |
</fo:block> | |
</fo:block-container> | |
<fo:block-container width="61mm" height="50.5mm" top="114.75mm" left="{$bleed+ 139}mm" position="absolute" block-align="center" text-align="center"> | |
<fo:block> | |
<xsl:call-template name="crop-scale-image"> | |
<xsl:with-param name="content-width">61</xsl:with-param> | |
<xsl:with-param name="content-height">50</xsl:with-param> | |
<xsl:with-param name="imgurl"> | |
<xsl:value-of select="$property/pictures/picture[4]/filename/text()"/> | |
</xsl:with-param> | |
</xsl:call-template> | |
</fo:block> | |
</fo:block-container> | |
<fo:block-container top="172mm" left="{$bleed+10.037}mm" width="184.5" height="15.5" position="absolute"> | |
<fo:block xsl:use-attribute-sets="MainHeading"><xsl:value-of select="$title"/></fo:block> | |
</fo:block-container> | |
<fo:block-container top="184.75mm" left="{$bleed+10.037}mm" width="72.5" height="8.5" position="absolute"> | |
<fo:block xsl:use-attribute-sets="SubHeading1"><xsl:value-of select="$price"/></fo:block> | |
</fo:block-container> | |
<fo:block-container top="184.75mm" left="109.6mm" width="87.6mm" height="65.3mm" position="absolute"> | |
<xsl:for-each select="$property/*[starts-with(name(),'bullet')]"> | |
<xsl:if test=". != ''"> | |
<fo:list-block provisional-distance-between-starts="5mm" | |
provisional-label-separation="0mm" padding-left="4mm"> | |
<fo:list-item> | |
<fo:list-item-label end-indent="label-end()"> | |
<xsl:call-template name="bullet"> | |
<xsl:with-param name="width">3.1</xsl:with-param> | |
<xsl:with-param name="height">2.4</xsl:with-param> | |
</xsl:call-template> | |
</fo:list-item-label> | |
<fo:list-item-body start-indent="body-start()"> | |
<fo:block xsl:use-attribute-sets="BulletList"> | |
<xsl:apply-templates/> | |
</fo:block> | |
</fo:list-item-body> | |
</fo:list-item> | |
</fo:list-block> | |
</xsl:if> | |
</xsl:for-each> | |
</fo:block-container > | |
<fo:block-container top="235mm" left="158.6mm" width="11mm" height="8mm" position="absolute"> | |
<xsl:call-template name="globrix"> | |
<xsl:with-param name="width">11</xsl:with-param> | |
<xsl:with-param name="height">8</xsl:with-param> | |
</xsl:call-template> | |
</fo:block-container> | |
<fo:block-container top="235mm" left="171.1mm" width="11mm" height="8mm" position="absolute"> | |
<xsl:call-template name="primelocation"> | |
<xsl:with-param name="width">11</xsl:with-param> | |
<xsl:with-param name="height">8</xsl:with-param> | |
</xsl:call-template> | |
</fo:block-container> | |
<fo:block-container top="235mm" left="182.2mm" width="13mm" height="10mm" position="absolute"> | |
<xsl:call-template name="findaproperty"> | |
<xsl:with-param name="width">13</xsl:with-param> | |
<xsl:with-param name="height">10</xsl:with-param> | |
</xsl:call-template> | |
</fo:block-container> | |
</fo:static-content> | |
<fo:flow flow-name="xsl-region-body"> | |
<fo:block> | |
<xsl:apply-templates select="$property/main_advert/"/> | |
<!-- <xsl:value-of select="$property/main_advert/text()"/> --> | |
</fo:block> | |
</fo:flow> | |
</fo:page-sequence> | |
</xsl:template> | |
<xsl:template name="crop-scale-image"> | |
<xsl:param name="content-width"/> | |
<xsl:param name="content-height"/> | |
<xsl:param name="imgurl"/> | |
<xsl:variable name="imginfourl"> | |
<xsl:text>http://www.example.com/ImageDataServlet-1.0/ImageDataServlet?imgsrc=</xsl:text> | |
<xsl:value-of select="$imgurl"/> | |
</xsl:variable> | |
<xsl:variable name="imginfo" select="document($imginfourl)"/> | |
<xsl:variable name="imgWidthmm" select="$imginfo/imginfo/imgwidth div 3.779527559"/> | |
<xsl:variable name="imgHeightmm" select="$imginfo/imginfo/imgheight div 3.779527559"/> | |
<xsl:variable name="xscale" select="$content-width div $imgWidthmm"/> | |
<xsl:variable name="yscale" select="$content-height div $imgHeightmm"/> | |
<xsl:variable name="scale"> | |
<xsl:choose> | |
<xsl:when test="$xscale >= $yscale"> | |
<xsl:value-of select="$xscale"/> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="$yscale"/> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:choose> | |
<xsl:when test="$yscale > $xscale"> | |
<fo:external-graphic scaling-method="resample-any-method" | |
height="{$content-height}mm" | |
width="{$content-width}mm" | |
src="{$imgurl}" | |
content-x="0mm" | |
content-y="0mm" | |
content-width="auto" | |
content-height="{$imgHeightmm * $scale }mm" | |
clip="auto" | |
movie="auto" | |
/> | |
</xsl:when> | |
<xsl:otherwise > | |
<fo:external-graphic scaling-method="resample-any-method" | |
height="{$content-height}mm" | |
width="{$content-width}mm" | |
src="{$imgurl}" | |
content-x="0mm" | |
content-y="0mm" | |
content-width="{$imgWidthmm * $scale }mm" | |
content-height="auto" | |
clip="auto" | |
movie="auto" | |
/> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:template> | |
<xsl:template name="scale-image"> | |
<xsl:param name="content-width"/> | |
<xsl:param name="content-height"/> | |
<xsl:param name="imgurl"/> | |
<xsl:variable name="imginfourl"> | |
<xsl:text>http://www.example.com/ImageDataServlet-1.0/ImageDataServlet?imgsrc=</xsl:text> | |
<xsl:value-of select="$imgurl"/> | |
</xsl:variable> | |
<xsl:variable name="imginfo" select="document($imginfourl)"/> | |
<xsl:variable name="imgWidthmm" select="$imginfo/imginfo/imgwidth div 3.779527559"/> | |
<xsl:variable name="imgHeightmm" select="$imginfo/imginfo/imgheight div 3.779527559"/> | |
<xsl:variable name="xscale" select="$content-width div $imgWidthmm"/> | |
<xsl:variable name="yscale" select="$content-height div $imgHeightmm"/> | |
<xsl:variable name="scale"> | |
<xsl:choose> | |
<xsl:when test="$xscale >= $yscale"> | |
<xsl:value-of select="$yscale"/> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="$xscale"/> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:variable> | |
<xsl:choose> | |
<xsl:when test="$yscale > $xscale"> | |
<fo:external-graphic scaling-method="resample-any-method" | |
width="{$content-width * $scale div $xscale}mm" | |
src="{$imgurl}" | |
content-x="0mm" | |
content-y="0mm" | |
content-width="{$imgWidthmm * $scale}mm" | |
content-height="{$imgHeightmm * $scale}mm" | |
clip="auto" | |
movie="auto" | |
/> | |
</xsl:when> | |
<xsl:otherwise > | |
<fo:external-graphic scaling-method="resample-any-method" | |
height="{$content-height * $scale div $yscale}mm" | |
src="{$imgurl}" | |
content-x="0mm" | |
content-y="0mm" | |
content-width="{$imgWidthmm * $scale}mm" | |
content-height="{$imgHeightmm * $scale}mm" | |
clip="auto" | |
movie="auto" | |
/> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:template> | |
<xsl:template name="loose_nasty_entities"> | |
<xsl:param name="thisstring" select="."/> | |
<xsl:variable name="thisstring1"> | |
<xsl:call-template name="replace"> | |
<xsl:with-param name="str" select="$thisstring"/> | |
<xsl:with-param name="search-for" select="'–'"/> | |
<xsl:with-param name="replace-with" select="'-'"/> | |
</xsl:call-template> | |
</xsl:variable> | |
<xsl:variable name="thisstring2"> | |
<xsl:call-template name="replace"> | |
<xsl:with-param name="str" select="$thisstring1"/> | |
<xsl:with-param name="search-for" select="''"/> | |
<xsl:with-param name="replace-with" select="''"/> | |
</xsl:call-template> | |
</xsl:variable> | |
<xsl:variable name="thisstring3"> | |
<xsl:call-template name="replace"> | |
<xsl:with-param name="str" select="$thisstring2"/> | |
<xsl:with-param name="search-for" select="'Â'"/> | |
<xsl:with-param name="replace-with" select="''"/> | |
</xsl:call-template> | |
</xsl:variable> | |
<xsl:variable name="thisstring4"> | |
<xsl:call-template name="replace"> | |
<xsl:with-param name="str" select="$thisstring3"/> | |
<xsl:with-param name="search-for" select="'é'"/> | |
<xsl:with-param name="replace-with" select="'é'"/> | |
</xsl:call-template> | |
</xsl:variable> | |
<xsl:variable name="thisstring5"> | |
<xsl:call-template name="replace"> | |
<xsl:with-param name="str" select="$thisstring4"/> | |
<xsl:with-param name="search-for" select="'amp;'"/> | |
<xsl:with-param name="replace-with" select="''"/> | |
</xsl:call-template> | |
</xsl:variable> | |
<xsl:value-of select="$thisstring5"/> | |
</xsl:template> | |
<xsl:template name="guide"> | |
<fo:block-container position="absolute" top="0mm" left="0mm" bottom="{$bleed + 297 + $bleed}mm" right="{$bleed + 210 + $bleed}mm" > | |
<fo:block option-group="Cut and Fold Marks" font-size="0.001pt"> | |
<fo:instream-foreign-object> | |
<svg | |
xmlns="http://www.w3.org/2000/svg" | |
version="1.0" | |
width="{$bleed + 210 + $bleed}mm" | |
height="{$bleed + 297 + $bleed}mm" | |
viewBox="0 0 {$bleed + 210 + $bleed} {$bleed + 297 + $bleed}" | |
xml:space="preserve"> | |
<g style="fill:none;stroke:#ff0000;stroke-width:0.1"> | |
<rect x="{$bleed}" y="{$bleed}" width="210" height="297" /> | |
</g> | |
</svg> | |
</fo:instream-foreign-object> | |
</fo:block> | |
</fo:block-container> | |
</xsl:template> | |
<xsl:template match="text()"> | |
<xsl:call-template name="loose_nasty_entities"/> | |
</xsl:template> | |
<xsl:template name="replace"> | |
<xsl:param name="str" /> | |
<xsl:param name="search-for"/> | |
<xsl:param name="replace-with"/> | |
<xsl:choose> | |
<xsl:when test="contains($str,$search-for)"> | |
<xsl:value-of select="substring-before($str,$search-for)"/> | |
<xsl:copy-of select="$replace-with"/> | |
<xsl:call-template name="replace"> | |
<xsl:with-param name="str" select="substring-after($str,$search-for)"/> | |
<xsl:with-param name="search-for" select="$search-for"/> | |
<xsl:with-param name="replace-with" select="$replace-with"/> | |
</xsl:call-template> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="$str"/> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:template> | |
</xsl:stylesheet> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment