简体   繁体   中英

How do I transform nested tabcontrol elements in XML/XSLT to XSL-FO

I have a dynamic xml record that uses tabcontrols and tabpages and I need to create xsl-fo. However, I cannot find any references to solutions online. An excerpt from the xml is as follows:

<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>

There is not a lot of information given in your source XML you present nor in trying to understand what the desired "look" of the output is.

PDF Acroform fields are support in RenderX XEP with the proper license and ensuring you add the rx: Extension namespace. I just did a simple layout using the XSL below (note I added tags to you XML to make it a complete document as it is only a fragment):

<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>

The result is a fillable form field (uses some information like the @ID attribute in the source as the name of the field, the @Value as the default value and for multiline fields, using the @Size as the height in pixels.

The result is shown below, you can see the highlighted fields.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM