Xsl-fo How to render whole report but also single elements

怎甘沉沦 提交于 2019-12-11 18:04:28

问题


I have a document that consists of about 40 pages. It consists of nested report elements like sections, chapters, pictures, paragraphs, tables and charts.

Each element has an attribute "layout" and an attribute "pagemaster".

"pagemaster" should be responsible for which page-master-reference is used and "layout" for the appearance on the page. (like font styles etc)

My goal is that each element has its own render information based on these attributes, so that the complete document as well as each single element can be rendered on its own.

In addition, I need to manage the static-content individually. (For example, there are differences in the number of pages position for even and odd pages, or whether a section has a table of contents)

I have already tried to group my elements using the pagemaster attribute. This works fine and I can specify for each element which simple-page-master should be used.

Problems I get now for example if a section should have a table of contents. For this I would have to move a static page in front of it to ONLY render the table of contents.

Here is a rough overview of the structure of my xml code

<?xml version="1.0" encoding="utf-8"?>
<root>
    <report>
        <layout></layout>
        <namecontent>REPORT</namecontent>
        <reportelements>
            <section>
                <layout>section</layout>
                <pagemaster></pagemaster>
                <visible>true</visible>
                <startatnewpage>true</startatnewpage>
                <titlecontent>Preface</titlecontent>
                <subtitlecontent />
                <notes />
                <reportelements>
                    <picture>
                        <layout>picture_title</layout>
                        <pagemaster>TITLEPAGE</pagemaster>
                        <visible>true</visible>
                        <startatnewpage>false</startatnewpage>
                        <titlecontent>Titlepicture</titlecontent>
                        <subtitlecontent />
                        <notes />
                        <reportelements />
                        <path>files\Titelpicture_17350276.Jpeg</path>
                        <footnote>Footnote</footnote>
                    </picture>
                    <section>
                        <layout>section_wide</layout>
                        <pagemaster>DIN-A4-VERTICAL</pagemaster>
                        <!-- Section should have a table of content -->
                        <hastoc>true</hastoc>
                        <visible>true</visible>
                        <startatnewpage>true</startatnewpage>
                        <titlecontent>This Section is not indented</titlecontent>
                        <subtitlecontent />
                        <notes />
                        <reportelements>
                            <paragraph>
                                <layout>paragraph_indented.xsl</layout>
                                <pagemaster>DIN-A4-HORIZONTAL</pagemaster>
                                <visible>true</visible>
                                <startatnewpage>false</startatnewpage>
                                <titlecontent>This Paragraph is not indented</titlecontent>
                                <subtitlecontent />
                                <notes />
                                <reportelements />
                                <showtitle>true</showtitle>
                                <language>de</language>
                                <textcontent>
                                    TEXT OF Paragarph
                                </textcontent>
                            </paragraph>
                                  .
                                  .
                                  .
                          <!-- and so on -->

And here is a little insight into my grouping-page-sequence which should call the layouting templates

            .
<!-- simple-page-masters defined here -->  
            .
            .  
</fo:layout-master-set>

            <xsl:for-each-group select=".//reportelements/*[pagemaster != '']" group-adjacent="pagemaster">

                <fo:page-sequence master-reference="{current-grouping-key()}">
                    <xsl:call-template name="STATIC-CONTENT">
                        <xsl:with-param name="pageMaster" select="current-grouping-key()" />
                    </xsl:call-template>

                    <fo:flow flow-name="xsl-region-body">
                        <xsl:for-each select="current-group()">
                            <xsl:apply-templates select="." />
                        </xsl:for-each>
                    </fo:flow>
                </fo:page-sequence>

            </xsl:for-each-group>
        </fo:root>
    </xsl:template>

    <xsl:template name="STATIC-CONTENT">
        <xsl:param name="pageMaster" />
        <xsl:if test="$pageMaster = 'TITLEPAGE'">
            <fo:static-content flow-name="xsl-region-after">
                <fo:block text-align="right">
                    <fo:external-graphic src="url(file:C:\Logo.pdf)" content-width="6cm" />
                </fo:block>
            </fo:static-content>
        </xsl:if>
    </xsl:template>

</xsl:stylesheet>

My problem is that I have absolutely no idea how to get the flexibility as described above or if this is possible at all?

来源:https://stackoverflow.com/questions/57871721/xsl-fo-how-to-render-whole-report-but-also-single-elements

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!