xml – 静态内容但动态内容的XSL-FO页脚?
我目前有一个XSL文件,用于将
XML转换为FO格式(XSL-FO).
唯一的问题是页脚. 我需要显示从每个页面的页脚到其他页面之一的文本引用.这意味着我需要使页脚文本动态化. 例如,这里是每个页面的一些抽象文本: page 1: Topic A page 2: Topic B page 3: Topic C,Subtopic of A page 4: Topic D,Subtopic of A page 5: Topic E,Subtopic of B 想象一下“subtopic”部分作为每页显示的页脚. 考虑以下XML: <DATA_DS> <LIST_ITEMS> <ITEMS> <isChild>0</isChild> <myvalue>abc</myvalue> <isLastChild>0</isLastChild> </ITEMS> <ITEMS> <isChild>1</isChild> <myvalue>def</myvalue> <isLastChild>0</isLastChild> </ITEMS> <ITEMS> <isChild>1</isChild> <myvalue>ghi</myvalue> <isLastChild>0</isLastChild> </ITEMS> <ITEMS> <isChild>1</isChild> <myvalue>xyz</myvalue> <isLastChild>1</isLastChild> </ITEMS> </LIST_ITEMS> </DATA_DS> 而这个XSL: <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"> <xsl:output method="xml" indent="yes"/> <xsl:template match="/"> <fo:root> <fo:layout-master-set> <fo:simple-page-master master-name="parentLOBPage-master" page-width="11in" page-height="8.5in" margin-left="1.3in" margin-right="0.65in" margin-top="0.35in" margin-bottom="0.35in"> <fo:region-body region-name="body" margin-top="0.5in" margin-right="0.65in"/> <fo:region-after region-name="footer" extent="14mm" /> </fo:simple-page-master> <fo:simple-page-master master-name="childLOBPage-master" page-width="11in" page-height="8.5in" margin-left="1.3in" margin-right="0.65in" margin-top="0.35in" margin-bottom="0.35in"> <fo:region-body region-name="body" margin-top="0.5in" margin-right="0.65in"/> <fo:region-after region-name="footer" extent="14mm"/> </fo:simple-page-master> <fo:page-sequence-master master-name="parentLOBPage"> <fo:repeatable-page-master-reference master-reference="parentLOBPage-master"/> </fo:page-sequence-master> <fo:page-sequence-master master-name="childLOBPage"> <fo:repeatable-page-master-reference master-reference="childLOBPage-master"/> </fo:page-sequence-master> </fo:layout-master-set> <xsl:apply-templates/> </fo:root> </xsl:template> <xsl:template match="DATA_DS"> <xsl:for-each-group select="LIST_ITEMS/ITEMS" group-adjacent="isChild"> <xsl:choose> <xsl:when test="isChild = 0"> <fo:page-sequence master-reference="parentLOBPage"> <fo:static-content flow-name="footer"> <fo:table width="100%" table-layout="fixed" margin-top="5mm"> <fo:table-column column-width="80%"/> <fo:table-column column-width="20%"/> <fo:table-body> <fo:table-row> <fo:table-cell> <fo:block text-align="left" font-family="Arial" font-size="7pt" font-weight="normal">parent footer</fo:block> </fo:table-cell> <fo:table-cell> <fo:block text-align="right" font-family="Arial" font-size="7pt" font-weight="normal">Page <fo:page-number/> of <fo:page-number-citation ref-id="last-page" /></fo:block> </fo:table-cell> </fo:table-row> </fo:table-body> </fo:table> </fo:static-content> <fo:flow flow-name="body"> <xsl:for-each select="current-group()"> <xsl:apply-templates select="."/> </xsl:for-each> </fo:flow> </fo:page-sequence> </xsl:when> <xsl:otherwise> <fo:page-sequence master-reference="childLOBPage"> <fo:static-content flow-name="footer"> <fo:table width="100%" table-layout="fixed" margin-top="5mm"> <fo:table-column column-width="80%"/> <fo:table-column column-width="20%"/> <fo:table-body> <fo:table-row> <fo:table-cell> <fo:block text-align="left" font-family="Arial" font-size="7pt" font-weight="normal">child footer: <xsl:value-of select="myvalue"/></fo:block> </fo:table-cell> <fo:table-cell> <fo:block text-align="right" font-family="Arial" font-size="7pt" font-weight="normal">Page <fo:page-number/> of <fo:page-number-citation ref-id="last-page" /></fo:block> </fo:table-cell> </fo:table-row> </fo:table-body> </fo:table> </fo:static-content> <fo:flow flow-name="body"> <xsl:for-each select="current-group()"> <xsl:apply-templates select="."/> </xsl:for-each> <fo:block id="last-page"/> </fo:flow> </fo:page-sequence> </xsl:otherwise> </xsl:choose> </xsl:for-each-group> </xsl:template> <xsl:template match="ITEMS"> <fo:table width="100%" table-layout="fixed" margin-top="5mm"> <fo:table-column column-width="20%"/> <fo:table-column column-width="80%"/> <fo:table-body> <fo:table-row> <fo:table-cell> <fo:block text-align="left" font-family="Arial" font-size="10pt" font-weight="bold">big table</fo:block> </fo:table-cell> <fo:table-cell> <fo:block text-align="left" font-family="Arial" font-size="10pt" font-weight="bold">some stuff</fo:block> </fo:table-cell> </fo:table-row> </fo:table-body> </fo:table> <xsl:if test="isChild = 1 and isLastChild = 0"> <fo:block page-break-after="always"/> </xsl:if> </xsl:template> </xsl:stylesheet> 由于我将每个页面的大部分内容都包含在一个fo:table中,而一些表格溢出到两个页面上,我不能只在每个表格后面放置“动态页脚文本”,因为它不会显示在每个页面上. 所以,我认为我使用fo:static-content是不合适的,即使它是我动态显示页码所需要的(即y的第x页).输出显示,对于每个子页脚页面,显示的值为“def”,这是列表中的第一个“子”.所以,fo:static-content在第一次执行时填充自身,并且不会为后续页面更新……所以我的方法是错误的.我需要一些关于如何修改我的方法的指导…… 有关如何让我的页脚按照我的XSL-FO情况需要的方式工作的任何建议? 解决方法
您的代码没有针对静态内容中的动态内容进行适当的构建.
您缺少的概念是您的页脚需要“检索您在流程中即时设置的标记”.所有页面的一个页脚从页面内容中检索一个标记类,并在流中的点处更改标记,并且检索将获取最新的标记(或其他选项). 因此,您只需要一个具有“Page x of y”位的单个页脚,并且您需要包含一个检索特定类的标记的页脚.然后,在您的流程中,使用您的所有主题和子主题,当您到达每个主题的第一项时,您可以使用要在页脚中查看的文本定义标记. 您的XSLT需要生成的XSL-FO输出是: <fo:static-content> ... page x of y stuff ... <fo:retrieve-marker retrieve-class-name="topic"/> </fo:static-content> <fo:flow> <fo:table> ... <fo:table-cell> <fo:marker marker-class-name="topic">Topic A</fo:marker> ... <fo:table-cell> <fo:marker marker-class-name="topic">Topic B</fo:marker> ... <fo:table-cell> <fo:marker marker-class-name="topic">Topic C,Subtopic of A</fo:marker> ... <fo:table-cell> <fo:marker marker-class-name="topic">Topic D,Subtopic of A</fo:marker> ... <fo:table-cell> <fo:marker marker-class-name="topic">Topic E,Subtopic of B</fo:marker> 我建议你查看我的PDF书籍免费“试用和购买”预览的第257页上标题为“静态内容中的动态内容”的框架: http://www.CraneSoftwrights.com/training/#pfux 使用图表对那里描述的标记的检索和定位属性有细微差别. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |