我有以下形式的测试人口统计数据(为演示目的而截断):
TreatmentArm Site-Subject Gender Age
Placebo 000001-000002 M 42
Placebo 000001-000043 F 23
Placebo 000003-000076 F 45
.
.
Active 000001-000003 M 56
Active 000003-000098 F 34 I可以生成一个具有头、页脚和显示上述结构中的数据的表的。然而,治疗手臂重复是没有必要的,通常会被副标题处理:
Treatment Arm: Placebo
Site-Subject Gender Age
000001-000002 M 42
000001-000043 F 23
000003-000076 F 45
<page-break>
Treatment Arm: Active
Site-Subject Gender Age
000001-000003 M 56
000003-000098 F 34 因此,处理臂的两个值是控制副标题中的文本,处理臂值的变化触发页面抛出。
我在这里尝试的语言是朱莉娅,到目前为止,它表现得很好。为了向PDF编写一个简单的报告,我需要使用一个名为Taro的包,它还使用了Mustache.js到朱莉娅的端口。在这里,Julia调用Java,Java使用Apache生成PDF。Julia调用XSL-FO模板,而胡子呈现函数将数据与模板结合起来。
因此,有两个源文件: Julia程序和XSL模板文件。第一,朱莉娅的消息来源,尽量删节:
using Taro
# init() once per session to set the Java classpath
Taro.init()
using Mustache
using DataFrames
# get the xsl-fo template
tmpl = Mustache.template_from_file("tables.fo.tmpl")
# get the data, process, sort and select columns
df = readtable("DM1.csv")
df[:sitesubj] = map(x->x[8:end], df[:usubjid])
df2 = sort(df[:, [:armcd, :arm, :sitesubj, :age, :sex]], cols = [:armcd, :sitesubj])
# Write the data to an Array of Dictionaries
d=Array(Dict, nrow(df2));
for i in 1:length(d)
d[i] = Dict{ASCIIString,Any}(
"armcd"=>df2[i, :armcd],
"arm"=>df2[i, :arm],
"sitesubj"=>df2[i, :sitesubj],
"age"=>df2[i, :age],
"sex"=>df2[i, :sex],
)
end
# Some Mustache magic. Render adds the data to the report template
# tn is a String, to is an IOStream
tn, to=mktemp()
fo=render(tmpl, D=d)
write(to, fo)
close(to)
Taro.fo(tn, "test_listing.pdf")现在,模板尽量删减,但留下一个有用的例子,尽管没有我需要的副标题:
<?xml version="1.0" encoding="UTF-8"?>
<fo:root font-family="Courier" font-size="10pt" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="A4-landscape"
margin-right="0.5cm"
margin-left="0.5cm"
margin-bottom="0.5cm"
margin-top="0.5cm"
page-width="29.7cm"
page-height="21cm">
<fo:region-body margin-top="4cm" margin-bottom="3cm"/>
<fo:region-before extent="8cm"/>
<fo:region-after extent="3cm"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="A4-landscape">
<!-- Headers -->
<fo:static-content flow-name="xsl-region-before">
<fo:block line-height="14pt" font-size="8pt" text-align-last="justify">ACME Corp
<fo:leader leader-pattern="space" />
CONFIDENTIAL
</fo:block>
<fo:block line-height="14pt" font-size="8pt" text-align-last="justify">XYZ123 / Anti-Hypertensive
<fo:leader leader-pattern="space" />
Draft
</fo:block>
<fo:block line-height="14pt" font-size="8pt" text-align="left">Protocol XYZ123</fo:block>
<fo:block line-height="14pt" font-size="8pt" text-align="center">Study XYZ123</fo:block>
<fo:block line-height="14pt" font-size="8pt" text-align="center">Listing of Demographic Data by Treatment Arm</fo:block>
<fo:block line-height="14pt" font-size="8pt" text-align="center">All Subjects</fo:block>
<fo:block text-align="left">
<!-- Here is where I need to add the current ARM value in a sub-title -->
<!-- fo:retrieve-marker ?? -->
</fo:block>
</fo:static-content>
<!-- Footers -->
<fo:static-content flow-name="xsl-region-after">
<fo:block line-height="14pt" font-size="8pt" text-align="left">A long explanatory text</fo:block>
<fo:block line-height="14pt" font-size="8pt" text-align="left">All subjects are included in the listing including the screen failures</fo:block>
<fo:block line-height="14pt" font-size="8pt" text-align="left">All measurements were taken at the screening visit</fo:block>
<fo:block line-height="14pt" font-size="8pt" text-align-last="left"> Page <fo:page-number/> of <fo:page-number-citation ref-id="end"/>
</fo:block>
</fo:static-content>
<fo:flow flow-name="xsl-region-body">
<!-- Here I need to capture the value of the current arm -->
<!-- Set a marker ?? -->
<!-- Cannot use {{#:D}} to {{/:D}} as this captures values across all rows -->
<fo:table table-layout="fixed" width="100%" >
<fo:table-column column-width="2cm"/>
<fo:table-column column-width="6cm"/>
<fo:table-column column-width="2cm"/>
<fo:table-column column-width="3cm"/>
<fo:table-header border-bottom-style="solid" border-top-style="solid">
<fo:table-row space-after="10px">
<fo:table-cell>
<fo:block>Arm</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>Site ID - Subject ID</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>Age</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>Gender</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-header>
<fo:table-body border-bottom-style="solid">
{{#:D}}
<fo:table-row keep-together.within-page="always">
<fo:table-cell>
<fo:block>{{arm}}</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>{{sitesubj}}</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>{{age}}</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>{{sex}}</fo:block>
</fo:table-cell>
</fo:table-row>
{{/:D}}
</fo:table-body>
</fo:table>
<fo:block id="end"/>
</fo:flow>
</fo:page-sequence>
</fo:root>这里的问题之一是技术的混合以及如何解决这个问题。我需要预先总结在朱莉娅,并传递另一个字典,只有‘安慰剂’和‘活动’值到模板。即便如此,必须有某种机制来识别模板中的位置。我认为不可能将XSL指令添加到混合程序中,因此模板中的逻辑无法实现。正如XSL文件中的注释所表明的那样,也许方法是设置和检索标记,但是对“BY组中的第一行”的识别似乎并不存在。我希望我错了,这是可能的。
寻呼问题似乎已由
<fo:table-row keep-together.within-page="always">但这不像说‘当达到这个条件时,抛出一个页面。’
所以,如果有人有建议的话,我很乐意测试它们。非常感谢。
发布于 2016-11-13 03:28:01
由于胡子在设计上是“无逻辑的”,所以我会在“朱莉娅”中总结一下这一点。传入外部数组。该数组中的每一行都有两列。第一列包含"Arm",第二列包含另一个数组,包含该"Arm“的数据。
此外,子头不应该在static-content中。它应该是流内容的一部分。我是不是漏掉了什么?
这些更改,再加上keep-together,应该会满足您的需要。
https://stackoverflow.com/questions/40367970
复制相似问题