gpt4 book ai didi

java - XSL 多列切换

转载 作者:行者123 更新时间:2023-12-02 09:41:19 24 4
gpt4 key购买 nike

我有一个 xml,其中列出了客户调用的电话,我需要将其显示在两列中。根据调用次数,列表可以是单页-单栏、单页-双栏或多页-双栏。

我必须使用基本的 apace fop,并且无法访问天线室或类似的库。

当我使用 for-each 时,我可以显示调用,但只能显示在单个列上。我这辈子都无法进入双栏。

我最接近的是下面@Eliot Kimber 的视频,但就是无法回避这样做

https://www.youtube.com/watch?v=x6pe7KXicpA

我尝试使用列模式,但这又只是在一列中列出所有调用

我的 XML 如下所示。

<CallsMade fromNumber="987654321">
<CallItem>
<DialledNumber>0123456789</DialledNumber>
<DateTime>2019-07-15 15:35:35</DateTime>
<Duration>00:04:23</Duration>
<Cost>$1.24</Cost>
</CallItem>
<CallItem>
<DialledNumber>0123456790</DialledNumber>
<DateTime>2019-07-15 15:36:35</DateTime>
<Duration>00:04:24</Duration>
<Cost>$1.25</Cost>
</CallItem>
<CallItem>
<DialledNumber>0123456791</DialledNumber>
<DateTime>2019-07-15 15:37:35</DateTime>
<Duration>>00:04:25</Duration>
<Cost>$1.26</Cost>
</CallItem>
<CallItem>
<DialledNumber>0123456792</DialledNumber>
<DateTime>2019-07-15 15:38:35</DateTime>
<Duration>>00:04:26</Duration>
<Cost>$1.27</Cost>
</CallItem>
<CallItem>
<DialledNumber>0123456793</DialledNumber>
<DateTime>2019-07-15 15:39:35</DateTime>
<Duration>>00:04:27</Duration>
<Cost>$1.28</Cost>
</CallItem>
<CallItem>
<DialledNumber>0123456794</DialledNumber>
<DateTime>2019-07-15 15:40:35</DateTime>
<Duration>>00:04:28</Duration>
<Cost>$1.29</Cost>
</CallItem>
<CallItem>
<DialledNumber>0123456795</DialledNumber>
<DateTime>2019-07-15 15:41:35</DateTime>
<Duration>>00:04:29</Duration>
<Cost>$1.30</Cost>
</CallItem>
<CallItem>
<DialledNumber>0123456931</DialledNumber>
<DateTime>2019-07-15 17:57:34</DateTime>
<Duration>00:06:45</Duration>
<Cost>$2.66</Cost>
</CallItem>
<CallsMade>`

XSL 可以进入多个页面,但下面是单列

<fo:block-container start-indent="0mm" left="5mm" width="48%" span="all">
<fo:table table-layout="fixed" width="100%" font-size="5pt" text-align="center" display-align="center" span="all">
<fo:table-column column-width="proportional-column-width(10)"/>
<fo:table-column column-width="proportional-column-width(15)"/>
<fo:table-column column-width="proportional-column-width(12)"/>
<fo:table-column column-width="proportional-column-width(8)"/>
<fo:table-body font-size="95%" >
<xsl:for-each select="CallItem">
<fo:table-row height="4mm" text-align="center" display-align="center">
<fo:table-cell>
<fo:block>
<xsl:value-of select="DialledNumber"/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
<xsl:value-of select="DateTime"/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
<xsl:value-of select="Duration"/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
<xsl:value-of select="Cost"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:for-each>
</fo:table-body>
</fo:table>
</fo:block-container>

我想知道是否有人可以帮我显示如下列表

enter image description here

最佳答案

看来您确实只需要知道您的 CallItem 是否少于 60 个。如果少于 60,则使表跨越两列,如果不是,则使其跨越一列。正常分页将负责跨列和页面拆分表格。

<xsl:template match="/">
<fo:root xml:lang="en">
<fo:layout-master-set>
<fo:simple-page-master master-name="spm">
<fo:region-body column-count="2" margin="36pt" />
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="spm">
<fo:flow flow-name="xsl-region-body">
<xsl:apply-templates />
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>

<xsl:template match="CallsMade">
<fo:block span="all">
<xsl:value-of select="@fromNumber" />
</fo:block>
<fo:block-container>
<xsl:if test="count(CallItem) &lt; 60">
<xsl:attribute name="span">all</xsl:attribute>
</xsl:if>
<fo:table table-layout="fixed" width="100%" font-size="5pt" text-align="center" display-align="center" span="all">
<fo:table-column column-width="proportional-column-width(10)"/>
<fo:table-column column-width="proportional-column-width(15)"/>
<fo:table-column column-width="proportional-column-width(12)"/>
<fo:table-column column-width="proportional-column-width(8)"/>
<fo:table-body font-size="95%" >
<xsl:apply-templates select="CallItem" />
</fo:table-body>
</fo:table>
</fo:block-container>
</xsl:template>

<xsl:template match="CallItem">
<fo:table-row height="4mm" text-align="center" display-align="center">
<fo:table-cell>
<fo:block>
<xsl:value-of select="DialledNumber"/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
<xsl:value-of select="DateTime"/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
<xsl:value-of select="Duration"/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
<xsl:value-of select="Cost"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:template>

关于java - XSL 多列切换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57046340/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com