如何将XML / XSLT中的嵌套tabcontrol元素转换为XSL-FO

时间:2016-09-27 11:36:27

标签: xml xslt xsl-fo

我有一个使用tabcontrols和tabpages的动态xml记录,我需要创建xsl-fo。但是,我找不到任何在线解决方案的参考。 xml的摘录如下:

<Textbox ID="Textbox_Comments_Multiline_5" Field="Case Comments:" Value=""   Size="600" Length="" Extender="TextBoxWatermark~  " Align="left" LabSize="" HelpMessage="" RPosition="0" isSpecific="true" Position="505" DefaultValue="" />
<Tabcontrol ID="Tabcontrol1" Position="700">
<Tabpage ID="Tabpage_Notification" Field="NOTIFICATION" Size="" Extender="" Align="" HelpMessage="" Position="1000">
  <Linebreak ID="Linebreak_Notification_1" RPosition="0" Position="1001" />
  <Combobox ID="Combobox_HPTOffice" Field="Health Protection Office:" Value="Please select" ValuesLookup="HPTOffice" Size="" Length="" Extender="" Align="" LabSize="180" HelpMessage="" RPosition="0" Position="1010" />
  <Linebreak ID="Linebreak_Notification_5" RPosition="0" Position="1011" />
  <Datebox ID="Datebox_NotificationDate" Field="Notification Date:" Value="1900-01-01" Size="100" Length="" Extender="" Align="right" LabSize="180" HelpMessage="" RPosition="0" Position="1020" />
  <Linebreak ID="Linebreak_Notification_10" RPosition="0" Position="1021" />
  <Textbox ID="Textbox_NotifiedBy" Field="Notified by:" Value="" Size="400" Length="" Extender="TextBoxWatermark~  " Align="left" LabSize="180" HelpMessage="" RPosition="0" Position="1030" />
  <Linebreak ID="Linebreak_Notification_15" RPosition="0" Position="1031" />
  <Textbox ID="Textbox_NotifierDesignation_Multiline_3" Field="Notifier Designation:" Value="" Size="600" Length="" Extender="TextBoxWatermark~  " Align="left" LabSize="" HelpMessage="Notifier details" RPosition="0" Position="1040" />
  <Linebreak ID="Linebreak_Notification_20" RPosition="0" Position="1041" />
  <Linebreak ID="Linebreak_Notification_25" RPosition="0" Position="1042" />
  <Textbox ID="Textbox_ResponsibleClinicianDetails_Multiline_5" Field="Responsible Clinician Details:" Value="" Size="600" Length="" Extender="TextBoxWatermark~  " Align="left" LabSize="" HelpMessage="" RPosition="0" Position="1050" />
  <Linebreak ID="Linebreak_Notification_30" RPosition="0" Position="1051" />
  <Linebreak ID="Linebreak_Notification_35" RPosition="0" Position="1052" />
  <Combobox ID="Combobox_SourceOfSpecimen" Field="Source Of Specimen:" Value="Please select" ValuesLookup="SourceOfSpecimen" Size="" Length="" Extender="" Align="" LabSize="180" HelpMessage="" RPosition="0" Position="1060" />
  <Linebreak ID="Linebreak_Notification_40" RPosition="0" Position="1061" />
  <Textbox ID="Textbox_SourceOfSpecimenOtherSpecify" Field="If other specify:" Value="" Size="300" Length="" Extender="TextBoxWatermark~  " Align="left" LabSize="180" HelpMessage="" RPosition="0" Position="1070" />
  <Linebreak ID="Linebreak_Notification_45" RPosition="0" Position="1071" />
  <Combobox ID="Combobox_Laboratory_InitialNotification" Field="Source Laboratory:" Value="Please select" ValuesLookup="Laboratory" Size="" Length="" Extender="" Align="" LabSize="180" HelpMessage="" RPosition="0" Position="1080" />
  <Linebreak ID="Linebreak_Notification_50" RPosition="0" Position="1081" />
  <Linebreak ID="Linebreak_Notification_60" RPosition="0" Position="1091" />
</Tabpage>

1 个答案:

答案 0 :(得分:2)

您的源XML中没有提供很多信息,也没有尝试理解输出所需的“外观”。

PDF在AcderX XEP中支持具有适当许可证的Acroform字段,并确保添加rx:Extension命名空间。我刚刚使用下面的XSL做了一个简单的布局(注意我给你添加了一些标签,使它成为一个完整的文档,因为它只是一个片段):

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:rx="http://www.renderx.com/XSL/Extensions" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
    <fo:root>
        <fo:layout-master-set>
            <fo:simple-page-master master-name="page" page-width="8.5in" page-height="11in"
                margin-top="0.5in" margin-bottom="0.5in">
                <fo:region-body region-name="body" margin-left="0.5in" margin-right="0.5in"/>
            </fo:simple-page-master>
        </fo:layout-master-set>
        <fo:page-sequence master-reference="page">
            <fo:flow flow-name="body">
                <xsl:apply-templates/>
            </fo:flow>
        </fo:page-sequence>
    </fo:root>
</xsl:template>
<xsl:template match="Tabcontrol">
    <fo:block margin="10pt" border-top="3pt solid silver">
        <xsl:apply-templates/>
    </fo:block>
</xsl:template>
<xsl:template match="Tabpage">
    <fo:block margin-left="10pt" margin-top="3pt">
        <xsl:value-of select="@Field"/>
    </fo:block>
    <fo:block margin="10pt" border="1pt solid black">
        <xsl:apply-templates/>
    </fo:block>
</xsl:template>
<xsl:template match="Linebreak">
    <fo:block>
        <fo:leader/>
    </fo:block>
</xsl:template>
<xsl:template match="Combobox">
    <fo:block margin-left="10pt" margin-right="10pt"  keep-with-next.within-page="always">
        <xsl:value-of select="@Field"/>
    </fo:block>
    <fo:block-container  margin-left="10pt" margin-right="10pt">
        <rx:pdf-form-field name="{@ID}">
            <rx:pdf-form-field-combobox background-color="wheat"
                border-width="1pt" border-style="solid"
                border-color="silver">
                <!-- You would need to define your selections here -->
                <rx:pdf-form-field-option text="option1"/>
                <rx:pdf-form-field-option text="option2"/>
                <rx:pdf-form-field-option text="option3"/>
                <rx:pdf-form-field-option text="option4"/>
                <rx:pdf-form-field-option text="option5"/>
                <rx:pdf-form-field-option text="option6"/>
            </rx:pdf-form-field-combobox>
        </rx:pdf-form-field>
        <fo:block>
            <fo:leader/>
        </fo:block>
    </fo:block-container>
</xsl:template>
<xsl:template match="Textbox | Datebox">
    <fo:block margin-left="10pt" margin-right="10pt" keep-with-next.within-page="always">
        <xsl:value-of select="@Field"/>
    </fo:block>
    <fo:block-container margin-left="10pt" margin-right="10pt">
        <xsl:if test="@Size != ''">
            <xsl:attribute name="height">
                <xsl:value-of select="concat(@Size,'px')"/>
            </xsl:attribute>
        </xsl:if>
        <rx:pdf-form-field name="{@Field}">
            <rx:pdf-form-field-text border-width="1pt" border-style="solid"
                border-color="silver" color="blue" font-size="10pt">
                <xsl:if test="@Size != ''">
                    <xsl:attribute name="multiline">
                        <xsl:text>true</xsl:text>
                    </xsl:attribute>
                </xsl:if>
                <xsl:attribute name="text">
                    <xsl:value-of select="@Value"/>
                </xsl:attribute>
            </rx:pdf-form-field-text>
        </rx:pdf-form-field>
        <fo:block>
            <fo:leader/>
        </fo:block>
    </fo:block-container>
</xsl:template>
</xsl:stylesheet>

结果是一个可填写的表单字段(使用一些信息,如源中的@ID属性作为字段的名称,@ Value作为默认值,对于多行字段,使用@Size作为高度,以像素为单位

结果如下所示,您可以看到突出显示的字段。

enter image description here