Varying or Conditional static-content in XSLT
I have a question about producing varying static content for pages, based on page number. i.e I need a different pag开发者_StackOverflow社区e header format for the first page and an entire different format for the subsequent pages.
I have made use of fo:conditional-page-master-reference to select amongst two separate master pages. But i'm unable to specify the conditions for the static content present in that master page. i.e the static content by definition applies to all my pages (which is not what i desire)
My question is:
Is it possible to describe such alternating or conditional static-content with the XSL page model (simple-page-master).
Regards, Srivatsa
You can modify your fo:static-content
when you output it in your fo:page-sequence
. By using fo:marker
and fo:retrieve-marker
, you can have the static-content set based on info contained on a particular page. For example, anytime you encountered a revdate
attribute you could output an fo:marker
. You would retrieve the value of that marker in your fo:static-content
.
Example of fo:marker
:
<fo:marker marker-class-name="footerRevdate">
<xsl:value-of select="@revdate"/>
</fo:marker>
Example of fo:retrieve-marker
:
<fo:static-content flow-name="some_flow">
<fo:block>
<fo:retrieve-marker retrieve-class-name="footerRevdate" retrieve-boundary="page-sequence" retrieve-position="last-starting-within-page"/>
</fo:block>
</fo:static-content>
You can also set static-content directly. This content would apply to all pages in that page-sequence. (The content would/could change for each page-sequence.) For example, you could output a prefix before the page-number if the attribute chapnbr
was equal to 0
.
<xsl:template match="chapter">
<xsl:variable name="page-prefix">
<xsl:choose>
<xsl:when test="number(@chapnbr)=0">INTRO-</xsl:when>
<xsl:otherwise/>
</xsl:choose>
</xsl:variable>
<fo:page-sequence master-reference="Body" font-family="Arial" font-size="10pt" force-page-count="even">
<fo:static-content flow-name="Even_Page_regionafter">
<fo:block>
<xsl:value-of select="concat('Page ',$page-prefix)"/><fo:page-number/>
</fo:block>
</fo:static-content>
<fo:flow flow-name="xsl-region-body">
<fo:block>
<xsl:apply-templates/>
</fo:block>
</fo:flow>
</fo:page-sequence>
</xsl:template>
Here you go ....
<fo:layout-master-set>
<fo:simple-page-master fo:master-name="Letter Page" fo:page-width="215.9mm" fo:page-height="279.4mm">
<fo:region-body fo:region-name="xsl-region-body" fo:background-color="rgb(204,255,255)" fo:margin="50mm 17.78mm 17.78mm 17.78mm"/>
<fo:region-after fo:region-name="xsl-region-after" fo:extent="17.78mm"/>
<fo:region-start fo:region-name="xsl-region-start" fo:extent="17.78mm"/>
<fo:region-end fo:region-name="xsl-region-end" fo:extent="17.78mm"/>
<fo:region-before fo:region-name="xsl-region-before" fo:extent="0.7in"/></fo:simple-page-master>
<fo:simple-page-master fo:master-name="A4" fo:page-height="297.180mm" fo:page-width="210.82mm">
<fo:region-body fo:region-name="xsl-region-body" fo:background="rgb(255,255,153)" fo:margin="0.7in"/>
<fo:region-before fo:region-name="A4Header" fo:extent="0.7in" fo:display-align="after"/>
<fo:region-after fo:region-name="xsl-region-after" fo:extent="0.7in"/>
<fo:region-start fo:region-name="xsl-region-start" fo:extent="0.7in"/>
<fo:region-end fo:region-name="xsl-region-end" fo:extent="0.7in"/>
</fo:simple-page-master>
<!--This complex master page selects a Letter Page for the first page and the A4 page for the rest of the pages -->
<fo:page-sequence-master fo:master-name="ComplexMaster1">
<fo:repeatable-page-master-alternatives fo:maximum-repeats="no-limit">
<fo:conditional-page-master-reference fo:master-reference="Letter Page" fo:page-position="first"/>
<fo:conditional-page-master-reference fo:master-reference="A4"/>
</fo:repeatable-page-master-alternatives>
</fo:page-sequence-master>
</fo:layout-master-set>
精彩评论