0

拥有一个主 DocBook “book.xml”,我想包括几篇 DocBook 文章,比如 x.xml 和 y.xml。(我通过使用

  <xi:include href="generated_schemata/x/x.xml"/>

这些文章 x 和 y 是从 OxygenXML 和文档 XSD 模式(x.xsd 和 y.xsd)生成的。在不同的架构中,我有相同的元素名称(比如“A”)。

docbkx 抱怨(我明白为什么),虽然它试图将文章 x 和 y 包含到 book.xml 中以呈现 PDF,但存在多个 ID 实例,即 A:

Failed to execute goal com.agilejava.docbkx:docbkx-maven-plugin:2.0.17:generate-pdf (default) on project docbook: 
Failed to transform to fo: org.apache.fop.fo.ValidationException: Property ID "A" (found on "fo:block") previously used; ID values must be unique within a document!

关于自动分离这些实例的任何想法?也许通过自动添加前缀?

(我了解,我可以手动更改 x.xml 和 y.xml 以免发生冲突;但是,由于频繁更改,这是错误的来源。或者,我可以更改架构规范,这不是一个选项)。

4

3 回答 3

1

这是 Bob Stayton 的一个秘诀,如何修改 xsl 以避免输出中出现重复的 ID:http: //www.sagehill.net/docbookxsl/DuplicateIDs.html#ModifyIdValues

于 2018-03-02T07:22:39.573 回答
1

不确定它是否有助于您的特定情况,但 Oxygen 19.1 支持 XInclude 1.1 并且在 xi:include 1.1 中有一个功能可以让您更改包含元素的 ID 属性:

https://www.w3.org/TR/xinclude-11/#attribute-copying

但这仅在从 Oxygen 发布时有效,在使用外部构建系统时无效。

于 2018-03-02T10:25:50.867 回答
0

两种解决方案——来自爱德华西藏和来自拉杜科拉武——完美结合。所以,简而言之,我描述了我的解决方案 - 仍然不完美但有效:我的主文件“books.xml”使用了几个包含,例如:

<xi:include href="generated_schemata/services/services.xml" ns3:root="one"/>
<xi:include href="generated_schemata/systems/systems.xml" ns3:root="two"/>

这两个包含文件都是由 OxygenXML 生成的,并且是 schemata 的文档。

我的 Maven 配置包括:

<plugin>
            <groupId>com.agilejava.docbkx</groupId>
            <artifactId>docbkx-maven-plugin</artifactId>
            <version>2.0.17</version>
            <executions>
                <execution>
                    <goals>
                        <goal>generate-html</goal>
                        <goal>generate-pdf</goal>
                    </goals>
                    <phase>package</phase>
                </execution>
            </executions>
            <configuration>
                <paperType>A4</paperType>
                <xincludeSupported>true</xincludeSupported>
                <useExtensions>1</useExtensions>
                <fop1Extensions>1</fop1Extensions>
                <generatedSourceDirectory>${project.build.directory}/xinclude</generatedSourceDirectory>
                <includes>book.xml</includes>
                <foCustomization>src/docbkx/xsl/fo.xsl</foCustomization> 
                <xhtmlCustomization>src/docbkx/xsl/xhtml.xsl</xhtmlCustomization>
                <htmlCustomization>src/docbkx/xsl/xhtml.xsl </htmlCustomization>
                <chapterAutolabel>1</chapterAutolabel> 
                <sectionAutolabel>1</sectionAutolabel> 
                <sectionAutolabelMaxDepth>5</sectionAutolabelMaxDepth>                 <sectionLabelIncludesComponentLabel>true</sectionLabelIncludesComponentLabel>
                <postProcess>
                    <copy todir="${env.GENQ_HOME}/doc/extra/html/generated_schemata/services/img">
                        <fileset dir="src/docbkx/generated_schemata/services/img/">
                            <include name="**/*.css"/>
                            <include name="**/*.js"/>
                            <include name="**/*.png"/>
                            <include name="**/*.gif"/>
                            <include name="**/*.jpg"/>
                            <include name="**/*.jpeg"/>
                        </fileset>
                    </copy>
                    <copy todir="${env.GENQ_HOME}/doc/extra/html/generated_schemata/systems/img">
                        <fileset dir="src/docbkx/generated_schemata/systems/img/">
                            <include name="**/*.css"/>
                            <include name="**/*.js"/>
                            <include name="**/*.png"/>
                            <include name="**/*.gif"/>
                            <include name="**/*.jpg"/>
                            <include name="**/*.jpeg"/>
                        </fileset>
                    </copy>                     
                </postProcess>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>net.sf.docbook</groupId>
                    <artifactId>docbook-xml</artifactId>
                    <version>5.1b4-all</version>
                    <classifier>resources</classifier>
                    <type>zip</type>
                    <scope>runtime</scope>
                </dependency>
                <dependency>
                    <groupId>net.sf.offo</groupId>
                    <artifactId>fop-hyph</artifactId>
                    <version>2.0</version>
                </dependency>
            </dependencies>
        </plugin>

最后,附加的 XSL 包括:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            xmlns:fo="http://docbook.org/ns/docbook">
<!-- use the default xslt from docbkx -->
<xsl:import href="urn:docbkx:stylesheet"/>
<!-- change the way, the TOC is done, cf. http://www.sagehill.net/docbookxsl/TOCcontrol.html -->
<xsl:param name="generate.toc" select="'book toc'"/>
<xsl:param name="fop1.extensions" select="1"/>

<xsl:attribute-set name="monospace.verbatim.properties">
    <xsl:attribute name="wrap-option">wrap</xsl:attribute>
    <xsl:attribute name="hyphenation-character">\</xsl:attribute>
    <xsl:attribute name="font-family">Courier</xsl:attribute>
    <xsl:attribute name="font-size">9pt</xsl:attribute>
    <xsl:attribute name="keep-together.within-column">always</xsl:attribute>
</xsl:attribute-set>

<xsl:template name="object.id">
    <xsl:param name="object" select="."/>
    <xsl:variable name="id" select="@id"/>
    <xsl:variable name="xid" select="@xml:id"/>
    <xsl:variable name="preceding.id"
                  select="count(preceding::*[@id = $id])"/>
    <xsl:variable name="preceding.xid"
                  select="count(preceding::*[@xml:id = $xid])"/>
    <xsl:choose>
        <xsl:when test="$object/@id and $preceding.id != 0">
            <xsl:value-of select="concat($object/@id, $preceding.id)"/>
        </xsl:when>
        <xsl:when test="$object/@id">
            <xsl:value-of select="$object/@id"/>
        </xsl:when>
        <xsl:when test="$object/@xml:id and $preceding.xid != 0">
            <xsl:value-of select="concat($object/@xml:id, $preceding.xid)"/>
        </xsl:when>
        <xsl:when test="$object/@xml:id">
            <xsl:value-of select="$object/@xml:id"/>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="generate-id($object)"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<xsl:template match="table">
    <fo:table-and-caption>
        <fo:table-caption>
            <xsl:apply-templates select="caption"/>
        </fo:table-caption>
        <xsl:apply-templates select="tbody"/>
    </fo:table-and-caption>
</xsl:template>

<xsl:template match="caption">
    <fo:block>
        <xsl:apply-templates/>
    </fo:block>
</xsl:template>

<xsl:template match="tbody">
    <fo:table space-before="0.5em" space-after="0.5em" table-layout="fixed">
        <fo:table-header>
            <xsl:apply-templates select="tr[1]"/>
        </fo:table-header>
        <fo:table-body>
            <xsl:apply-templates select="tr[position() &gt; 1]"/>
        </fo:table-body>
    </fo:table>
</xsl:template>

</xsl:stylesheet>

希望有人可以从中受益。

有什么改进建议吗?

于 2018-03-06T15:38:25.773 回答