I'm stuck. I've got a series of sites that are using different
structures. One has its content in a div called "main", the other in a
div called "contentBoxInner". These are converted into PDF by the way of
a chunk of XSLT. I need some way of doing an "if", so basically if the
"main" div exists, use that as the page flow for the PDF, but if it
doesn't exist use the "contentBoxInner" div instead. I can get one or
the other working in isolation... but how about both???
main:
<fo:page-sequence master-reference="a4">
<xsl:apply-templates mode="header" select="//x:div[@id='header']"/>
<xsl:apply-templates mode="footer" select="//x:div[@id='footer']"/>
<xsl:apply-templates select="//x:div[@id='main']"/>
</fo:page-sequence>
contentBoxInner:
<fo:page-sequence master-reference="a4">
<xsl:apply-templates mode="header" select="//x:div[@id='header']"/>
<xsl:apply-templates mode="footer" select="//x:div[@id='footer']"/>
<xsl:apply-templates select="//x:div[@id='contentBoxInner']"/>
</fo:page-sequence>
full XSLT;
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet exclude-result-prefixes="x" version="1.1"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:x="http://www.w3.org/1999/xhtml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" method="xml" omit-xml-declaration="no"
version="1.0"/>
<xsl:param name="baseHref">http://localhost</xsl:param>
<xsl:template match="x:html">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master margin-bottom="1cm"
margin-left="1cm" margin-right="1cm"
margin-top="1cm" master-name="a4"
page-height="29.7cm" page-width="21cm">
<fo:region-before extent="2.5cm" precedence="true"/>
<fo:region-after extent="0.5cm" precedence="true"/>
<fo:region-body margin-bottom="0.6cm"
margin-top="2.6cm"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="a4">
<xsl:apply-templates mode="header"
select="//x:div[@id='title']"/>
<xsl:apply-templates mode="footer"
select="//x:div[@id='copyright']"/>
<xsl:apply-templates
select="//x:div[@id='contentBoxInner']"/>
</fo:page-sequence>
</fo:root>
</xsl:template>
<xsl:template match="x:div[@id='title']" mode="header">
<fo:static-content flow-name="xsl-region-before">
<fo:table border="#000000 0.03cm solid" padding="0.05cm"
table-layout="fixed">
<fo:table-column column-width="4cm"/>
<fo:table-column column-width="15cm"/>
<fo:table-body>
<fo:table-row>
<fo:table-cell display-align="center"
text-align="center">
<fo:block>
<fo:external-graphic
content-height="1.986in"
content-width="3.694in"
height="2cm" scaling="uniform"
text-align="center" width="3.72cm">
<xsl:attribute
name="src"><xsl:value-of select="concat($baseHref,
'/gsk/images/logo.vopen.gif')"/></xsl:attribute>
</fo:external-graphic>
</fo:block>
</fo:table-cell>
<fo:table-cell display-align="center">
<xsl:apply-templates mode="header"
select=".//x:h1"/>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:static-content>
</xsl:template>
<xsl:template match="x:h1" mode="header">
<fo:block background-color="#ffffff" color="#000000"
font-family="Arial, Helvetica, sans-serif" font-size="24pt"
font-weight="bold" margin-left="0.5cm" text-align="center">
<xsl:apply-templates/>
</fo:block>
</xsl:template>
<xsl:template match="x:h6" mode="header">
<fo:block background-color="#ffffff" color="#000000"
font-family="Arial, Helvetica, sans-serif" font-size="8pt"
font-weight="bold" text-align="center">
<xsl:apply-templates/>
</fo:block>
</xsl:template>
<xsl:template match="x:em">
<fo:inline color="#000000">
<xsl:apply-templates/>
</fo:inline>
</xsl:template>
<!--<xsl:template match="x:div[@id='copyright']" mode="footer">
<fo:static-content flow-name="xsl-region-after">
<fo:block background-color="white" color="#666"
font-family="Arial, Helvetica, sans-serif"
font-size="8pt" text-align="center">
<xsl:apply-templates/>
</fo:block>
</fo:static-content>
</xsl:template>-->
<xsl:template match="x:div[@id='contentBoxInner']">
<fo:flow flow-name="xsl-region-body">
<fo:block>
<xsl:apply-templates/>
</fo:block>
<fo:block>
<xsl:apply-templates select="//x:div[@id='queryStatus']"/>
</fo:block>
</fo:flow>
</xsl:template>
<xsl:template match="x:table[@class='data']">
<xsl:variable name="numRows" select="count(.//x:tbody/x:tr)"/>
<xsl:variable name="numCols"
select="count(.//x:tbody/x:tr[1]/x:td)"/>
<xsl:variable name="ignoreCols"
select="count(.//x:tbody/x:tr[1]/x:td[@class='pdfignore'])"/>
<xsl:variable name="doubleWidthCols"
select="count(.//x:tbody/x:tr[1]/x:td[@class='doubleWidth'])"/>
<xsl:choose>
<xsl:when test="$numRows=1 and $numCols=1">
<fo:block text-align="center"><xsl:value-of
select=".//x:tbody/x:tr[1]/x:td"/></fo:block>
</xsl:when>
<xsl:otherwise>
<fo:table display-align="center" font-family="Courier New,
Courier, mono"
space-after="0.5cm" table-layout="fixed"
text-align="center">
<!-- <xsl:if
test="count(following:

:table[@class='data']) > 0">
<xsl:attribute name="break-after">page</xsl:attribute>
</xsl:if> -->
<xsl:variable name="colWidth" select="19.0 div ($numCols
- $ignoreCols + $doubleWidthCols)"/>
<xsl:apply-templates mode="columns"
select=".//x:tbody/x:tr[1]/x:td">
<xsl:with-param name="colWidth" select="$colWidth"/>
</xsl:apply-templates>
<xsl:apply-templates/>
</fo:table>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="x:td[@class = 'pdfignore']" mode="columns"/>
<xsl:template match="x:td" mode="columns">
<xsl:param name="colWidth" select="1"/>
<xsl:choose>
<xsl:when test="@class='doubleWidth'">
<fo:table-column column-width="{$colWidth * 2}cm"/>
</xsl:when>
<xsl:otherwise>
<fo:table-column column-width="{$colWidth}cm"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="x:table[@class='data']/x:thead">
<fo:table-header background-color="#dfe8fd" color="#000000"
font-size="8pt"
font-weight="bold" line-height="12pt">
<xsl:apply-templates/>
</fo:table-header>
</xsl:template>
<xsl:template match="x:table[@class='data']/*/x:tr">
<fo:table-row>
<xsl:apply-templates/>
</fo:table-row>
</xsl:template>
<xsl:template match="x:table[@class='data']/x:tfoot">
<fo:table-footer background-color="#dfe8fd" color="#000000"
font-size="8pt"
font-weight="bold" line-height="12pt">
<xsl:apply-templates/>
</fo:table-footer>
</xsl:template>
<xsl:template match="x:table[@class='data']/*/*/x:th">
<fo:table-cell border="0.025cm solid #999999"
border-collapse="collapse">
<xsl:if test="@colspan">
<xsl:attribute name="number-columns-spanned">
<xsl:value-of select="@colspan"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="@rowspan">
<xsl:attribute name="number-rows-spanned">
<xsl:value-of select="@rowspan"/>
</xsl:attribute>
</xsl:if>
<fo:block>
<xsl:apply-templates/>
</fo:block>
</fo:table-cell>
</xsl:template>
<xsl:template match="x:table[@class='data']/*/*/x:td">
<fo:table-cell border="0.025cm solid #999999"
border-collapse="collapse">
<xsl:if test="@colspan">
<xsl:attribute name="number-columns-spanned">
<xsl:value-of select="@colspan"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="@rowspan">
<xsl:attribute name="number-rows-spanned">
<xsl:value-of select="@rowspan"/>
</xsl:attribute>
</xsl:if>
<xsl:choose>
<xsl:when test="@class='red'">
<xsl:attribute
name="background-color">#999</xsl:attribute>
<xsl:attribute name="color">black</xsl:attribute>
</xsl:when>
<xsl:when test="@class='green'">
<xsl:attribute
name="background-color">white</xsl:attribute>
<xsl:attribute name="color">black</xsl:attribute>
</xsl:when>
<xsl:when test="@class='amber'">
<xsl:attribute name="color">black</xsl:attribute>
<xsl:attribute
name="background-color">#ccc</xsl:attribute>
</xsl:when>
<xsl:when test="@class='empty'">
<xsl:attribute
name="background-color">#888</xsl:attribute>
<xsl:attribute name="color">white</xsl:attribute>
</xsl:when>
<xsl:when test="@class='label'">
<xsl:attribute
name="background-color">#dfe8fd</xsl:attribute>
<xsl:attribute name="color">#000000</xsl:attribute>
<xsl:attribute name="font-weight">bold</xsl:attribute>
<xsl:attribute name="text-align">right</xsl:attribute>
</xsl:when>
</xsl:choose>
<fo:block>
<xsl:apply-templates/>
</fo:block>
</fo:table-cell>
</xsl:template>
<xsl:template match="x:table[@class='data']/x:tbody">
<fo:table-body background-color="#ffffff" color="#000000"
font-size="8pt"
font-weight="normal" line-height="12pt">
<xsl:apply-templates/>
</fo:table-body>
</xsl:template>
<xsl:template match="x:h2">
<fo:block color="#cc0000" font-family="serif" font-size="14pt"
keep-with-next.within-page="always" space-after="0.3cm"
text-align="center">
<xsl:apply-templates/>
</fo:block>
</xsl:template>
<xsl:template match="x:img">
<fo:block break-after="page">
<fo:external-graphic scaling="uniform" text-align="center"
width="18cm">
<xsl:attribute name="height"><xsl:value-of
select="(@height div 400) * 12"/>cm</xsl:attribute>
<xsl:attribute name="content-height"><xsl:value-of
select="@height"/>px</xsl:attribute>
<xsl:attribute name="content-width"><xsl:value-of
select="@width"/>px</xsl:attribute>
<xsl:attribute name="src"><xsl:value-of
select="concat($baseHref, @src)"/></xsl:attribute>
</fo:external-graphic>
</fo:block>
</xsl:template>
<xsl:template match="x

l/x:li">
<fo:block><xsl:apply-templates /></fo:block>
</xsl:template>
<xsl:template match="x

l/x:li/x:ul/x:li">
<fo:block margin-left="2cm"><xsl:apply-templates /></fo:block>
</xsl:template>
<xsl:template match="x:hr">
<fo:block break-after="page" />
</xsl:template>
<!-- <xsl:template match="x:p"/> -->
<xsl:template match="x:h1"/>
<xsl:template match="x:h6"/>
<xsl:template match="x:head"/>
<xsl:template match="x:script"/>
<xsl:template match="//*[@class='pdfignore']"/>
<xsl:template match="x:div[@class='nocss']"/>
<xsl:template match="x:div[@id='heading']"/>
<xsl:template match="x:div[@id='menu']"/>
<xsl:template match="x:div[@id='validation']"/>
<xsl:template match="x:div[@id='footer']"/>
</xsl:stylesheet>
help! free cakes to whoever can point me in the right direction
--
x theSpaceGirl (miranda)
# lead designer @ <a style='text-decoration: underline;' href="http://www.dhnewmedia.com" target="_blank">http://www.dhnewmedia.com</a> #
# remove NO SPAM to email, or use form on website #<!-- ~MESSAGE_AFTER~ -->