0

我正在使用带有 Antenna House Formatter v6.3 的 XSL-FO 来设计飞行手册。

许多信息属于“如果条件 X 做这做那,否则做其他事情”的类型。在当前情况下,我有以下 XML:

<crewDrill>
    <case>
        <caseCond>Hot inside:</caseCond>
        <if>
            <caseCond>Yes</caseCond>
            <crewDrillStep>
                <para>Adjust thermostat</para>
            </crewDrillStep>
            <crewDrillStep>
                <para>Open the window</para>
            </crewDrillStep>
        </if>
    </case>
    <crewDrillStep>
        <para>Enjoy life</para>
    </crewDrillStep>
</crewDrill>

此 XML 的所需输出将是:

条件语句的所需输出

编辑:所以我担心使用 XSLT 将 XML 转换为 XSL-FO(包括 Antenna House Formatter 中的功能)所需的输出是否可行,如果是这样,解决问题的正确方法是什么?鉴于我对 XSL-FO 的了解,我能做到这一点的唯一方法是使用表。也许有更好的方法。

编辑 2:正如@Tomalak 指出的那样,这实际上是两个问题——XSL-FO 结构的外观以及 XSLT 转换的外观。我主要关心的是表示所需输出的 ​​XSL-FO 结构的外观。给定一个目标结构,我大概能够找出转换。很抱歉最初的问题不清楚,感谢@Tomalak 澄清了我的担忧。

使用的 XML 模式源自 S1000D 4.1 Crew 模式

4

1 回答 1

1

这里有一些 XSL 代码供您思考。这并不完美,但调整表格中的一些边框和列可以让你到达那里。

注意:我添加了一个单独的文档元素,以便我可以测试各种情况。

这个 XSL:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
        xmlns:fo="http://www.w3.org/1999/XSL/Format"
        version="1.0">
        <xsl:template match="/">
            <xsl:apply-templates/>
        </xsl:template>
        <xsl:template match="document">
            <fo:root font-family="Arial">
                <fo:layout-master-set>
                    <fo:simple-page-master master-name="page"
                        page-height="11in" page-width="8in"
                        margin-top=".5in" margin-left="1in" margin-right="1in" margin-bottom=".5in">
                        <fo:region-body/>
                    </fo:simple-page-master>
                </fo:layout-master-set>
                <fo:page-sequence master-reference="page">
                    <fo:flow flow-name="xsl-region-body" >
                        <xsl:apply-templates/>
                    </fo:flow>
                </fo:page-sequence>
            </fo:root>
        </xsl:template>
        <xsl:template match="crewdrill">
            <!-- whole diagram, put into a block -->
            <fo:block>
                <xsl:apply-templates/>
            </fo:block>
        </xsl:template>
        <xsl:template match="case">
            <!-- map to a table 2-row table, one for heading and one for the step(s) -->
            <fo:table>
                <fo:table-column column-width="12pt"/>
                <fo:table-column column-width="12pt"/>
                <fo:table-column column-width="12pt"/>
                <fo:table-column/>
                <fo:table-column column-width="prrportional-column-width(100)"/>
                <fo:table-body>
                    <fo:table-row>
                        <fo:table-cell number-columns-spanned="6">
                            <fo:block font-weight="bold">
                                <xsl:value-of select="caseCond"/>
                            </fo:block>
                        </fo:table-cell>
                    </fo:table-row>
                    <xsl:apply-templates/>
                </fo:table-body>
            </fo:table>
        </xsl:template>
        <xsl:template match="if">
            <fo:table-row>
                <fo:table-cell border-right="0.5pt solid black">
                    <fo:block text-align="right" margin-right="-1.5pt">◄&lt;/fo:block>
                </fo:table-cell>
                <fo:table-cell padding-left="-1.5pt">
                    <fo:block>►&lt;/fo:block>
                </fo:table-cell>
                <fo:table-cell>
                    <fo:block>─</fo:block>
                </fo:table-cell>
                <fo:table-cell border="0.5pt solid black" text-align="center">
                    <fo:block font-weight="bold">
                        <xsl:value-of select="caseCond"/>
                    </fo:block>
                </fo:table-cell>
                <fo:table-cell>
                    <fo:block><fo:leader/></fo:block>
                </fo:table-cell>
            </fo:table-row>
            <fo:table-row>
                <fo:table-cell border-right="0.5pt solid black">
                    <fo:block><fo:leader/></fo:block>
                </fo:table-cell>
                <fo:table-cell>
                    <fo:block><fo:leader/></fo:block>
                </fo:table-cell>
                <fo:table-cell>
                    <fo:block><fo:leader/></fo:block>
                </fo:table-cell>
                <fo:table-cell number-columns-spanned="2">
                    <xsl:apply-templates/>
                </fo:table-cell>
            </fo:table-row>
            <fo:table-row>
                <fo:table-cell border-right="0.5pt solid black">
                    <fo:block><fo:leader/></fo:block>
                </fo:table-cell>
                <fo:table-cell font-weight="bold" text-align="center" number-columns-spanned="4">
                    <fo:block>- END -</fo:block>
                </fo:table-cell>
            </fo:table-row>
        </xsl:template>
        <xsl:template match="crewDrillStep[not(parent::if)]">
            <xsl:variable name="num">
                <xsl:value-of select="count(preceding-sibling::crewDrillStep) + 1"/>
            </xsl:variable>
            <fo:table>
                <fo:table-body>
                    <fo:table-row>
                        <fo:table-cell border="0.5pt solid black" text-align="center">
                            <fo:block font-weight="bold">No</fo:block>
                        </fo:table-cell>
                        <fo:table-cell>
                            <fo:block><fo:leader></fo:leader></fo:block>
                        </fo:table-cell>
                    </fo:table-row>
                    <fo:table-row>
                        <fo:table-cell number-columns-spanned="2">
                            <xsl:apply-templates>
                                <xsl:with-param name="num" select="$num"/>
                            </xsl:apply-templates>
                        </fo:table-cell>
                    </fo:table-row>
                    <fo:table-row>
                        <fo:table-cell font-weight="bold" text-align="center" number-columns-spanned="5">
                            <fo:block>------ END ------</fo:block>
                        </fo:table-cell>
                    </fo:table-row>
                </fo:table-body>
            </fo:table>
        </xsl:template>
        <xsl:template match="crewDrillStep">
            <xsl:variable name="num">
                <xsl:value-of select="count(preceding-sibling::crewDrillStep) + 1"/>
            </xsl:variable>
            <xsl:apply-templates>
                <xsl:with-param name="num" select="$num"/>
            </xsl:apply-templates>
        </xsl:template>
        <xsl:template match="para">
            <xsl:param name="num"/>
            <fo:block>
                <xsl:text>(</xsl:text><xsl:value-of select="$num"/><xsl:text>) </xsl:text><xsl:value-of select="."/>
            </fo:block>
        </xsl:template>
        <xsl:template match="caseCond"/>
    </xsl:stylesheet>

产生这个输出:

在此处输入图像描述

于 2016-11-25T23:26:19.117 回答