【问题标题】:XSL-FO Layout conditional informationXSL-FO 布局条件信息
【发布时间】:2016-11-23 10:16:31
【问题描述】:

我正在使用带有 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 模式

【问题讨论】:

  • 好的,所以你有两个问题,你应该一个接一个地解决它们。 问题 1:是否存在 FOP XML 文档会导致 PDF 看起来像这样。答:我不知道。也许是通过表格的一些技巧,也许是通过 SVG。您的第一步应该是弄清楚这一点并手动编写相应的 XML,而不使用任何 XSLT。
  • 问题 2:给定所需的 FOP XML 和一些输入 XML,XSLT 会如何生成这个?当你解决了第一个问题时,你应该解决这个问题。这也比第一个问题容易得多。因此,一旦您知道要创建的目标 XML 是什么,您自己就可以轻松地完成工作了。
  • 我会说更好的方法是生成 SVG,就像@Tomalak 提到的那样。
  • SVG 可能只有在图表用于一页时才是一个好的解决方案。如果图表内允许中断,那么表格(带有列表)是一个不错的解决方案。

标签: xml xslt xsl-fo antenna-house


【解决方案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">◄</fo:block>
                </fo:table-cell>
                <fo:table-cell padding-left="-1.5pt">
                    <fo:block>►</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>

产生这个输出:

【讨论】:

  • 感谢您为帮助我做出的雄心勃勃的努力 :) 我以您的工作为起点。竖起大拇指。
猜你喜欢
  • 2014-08-19
  • 1970-01-01
  • 2013-01-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-14
  • 1970-01-01
  • 2013-08-18
相关资源
最近更新 更多