在书中包含多个docbook文章:具有相同ID的错误

时间:2018-02-28 14:35:31

标签: docbook oxygenxml

拥有一个主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,以便没有冲突;但是,由于频繁的更改,这是一个错误的来源。或者,我可以更改架构规范,这是不是一种选择)。

3 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:1)

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

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

但这只有在从Oxygen发布时才有效,而不是在使用外部构建系统时。

答案 2 :(得分:0)

来自Eduard Tibet和Radu Coravu的两种解决方案完美结合。所以,简而言之,我描述了我的解决方案 - 仍然不完美但工作: 我的主文件“books.xml”使用了几个include,例如:

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

希望有人可以从中受益。

有关改进的任何建议吗?