XSL模糊规则混乱

时间:2015-12-07 12:59:10

标签: xml xslt

我收到一个模棱两可的规则匹配错误,正在抛弃我。这是错误:

Recoverable error 
  XTRE0540: Ambiguous rule match for
  /dmodule/content[1]/description[1]/levelledPara[2]/levelledPara[4]/table[1]
Matches both "table[parent::levelledPara] | table[parent::proceduralStep]" on line 3047 of
  file:/c:/users/c79460/AppData/Local/PWC%20PDF%20Generator/test3.xsl
and "table[not(parent::levelledPara)] | table[not(parent::proceduralStep)]" on line 2962
  of file:/c:/users/c79460/AppData/Local/PWC%20PDF%20Generator/test3.xsl

根据引用的两条规则及其匹配的路径,我看不出哪里有任何歧义。我觉得这个表有一个levelledPara父类似乎很明显,为什么我会得到规则匹配的歧义(parent :: levelledPara)?我确信我可能会遗漏一些荒谬简单的东西,希望一些新观点能够抓住它。是因为我有一个"或"在match语句中使用两个不同的父标签(levelledPara和proceduralStep)?

XSL:

<xsl:template match="table[not(parent::levelledPara)] | table[not(parent::proceduralStep)]">
    <xsl:variable name="TId" select="@id"/>
    <xsl:variable name="tCount">
        <xsl:number level="any" count="table" format="1"/>
    </xsl:variable>
    <fo:table table-layout="fixed" width="100%" id="{$TId}" ><!--margin-left="-10mm" -->
        <fo:table-column column-width="proportional-column-width(1)"/>
        <fo:table-header>
            <fo:table-row>
                <fo:table-cell>
                    <xsl:if test="title/text()">
                        <!--border="1 solid black" --><fo:block keep-with-next="always" text-align="center" padding-top="8pt" padding-bottom="2pt" space-after="2pt" margin-left="-10mm">
                            <fo:inline font-style="italic">Table <xsl:value-of select="$tCount"/>
                                <xsl:value-of select="concat(' - ', ./title)"/></fo:inline>
                            <fo:retrieve-table-marker retrieve-class-name="tab-cont" 
                                retrieve-position-within-table="first-starting" 
                                retrieve-boundary-within-table="table"/>
                        </fo:block>
                    </xsl:if>
                    <xsl:if test="not(title/text())">
                        <fo:block keep-with-next="always" text-align="center" space-after="2pt">
                            <fo:inline font-style="italic">Table <xsl:value-of select="$tCount"/>
                                </fo:inline>
                            <fo:retrieve-table-marker retrieve-class-name="tab-cont" 
                                retrieve-position-within-table="first-starting" 
                                retrieve-boundary-within-table="table"/>
                        </fo:block>
                    </xsl:if>
                </fo:table-cell>
            </fo:table-row>
        </fo:table-header>
        <fo:table-body>
            <fo:table-row>
                <fo:table-cell>
                    <fo:marker marker-class-name="tab-cont"/>
                    <fo:block/>
                </fo:table-cell>
            </fo:table-row>
            <fo:table-row>
                <fo:table-cell>
                    <fo:marker marker-class-name="tab-cont">&#x00A0;- (Continued)</fo:marker>
                    <fo:block keep-with-previous="always">
                        <fo:marker marker-class-name="tab-cont">&#x00A0;- (Continued)</fo:marker>
                        <fo:table table-layout="fixed" width="100%">
                            <xsl:for-each select="colspec">
                                <fo:table-column column-width="proportional-column-width(@colwidth)"/>
                            </xsl:for-each>
                            <fo:table-header>
                                <xsl:for-each select="./tgroup/thead/row">
                                    <fo:table-row>
                                        <xsl:apply-templates/>
                                    </fo:table-row>
                                </xsl:for-each>
                            </fo:table-header>
                            <fo:table-footer>
                                <fo:table-row>
                                    <xsl:for-each select="./tgroup/thead/row[1]/entry"><!--[position() &gt; 1]-->
                                        <fo:table-cell border-top-style="solid" border-top-color="black" border-collapse="collapse">
                                            <fo:block/>
                                        </fo:table-cell>
                                    </xsl:for-each>
                                </fo:table-row>
                            </fo:table-footer>
                            <fo:table-body>
                                <xsl:for-each select="./tgroup/tbody/row">
                                    <fo:table-row>
                                        <xsl:apply-templates/>
                                    </fo:table-row>
                                </xsl:for-each>
                                <xsl:if test="./tgroup/tfoot">
                                    <xsl:for-each select="./tgroup/tfoot/row">
                                        <fo:table-row>
                                            <xsl:apply-templates/>
                                        </fo:table-row>
                                    </xsl:for-each>
                                </xsl:if>
                            </fo:table-body>
                        </fo:table>
                    </fo:block>
                </fo:table-cell>
            </fo:table-row>
        </fo:table-body>
    </fo:table>
</xsl:template>

<xsl:template match="table[parent::levelledPara] | table[parent::proceduralStep]">
    <xsl:variable name="TId" select="@id"/>
    <xsl:variable name="tCount">
        <xsl:number level="any" count="table" format="1"/>
    </xsl:variable>
    <fo:table table-layout="fixed" width="93%" id="{$TId}" margin-left="-10mm"><!--margin-left="-10mm" -->
        <fo:table-column column-width="proportional-column-width(1)"/>
        <fo:table-header>
            <fo:table-row>
                <fo:table-cell>
                    <xsl:if test="title/text()">
                        <!--border="1 solid black" --><fo:block keep-with-next="always" text-align="center" padding-top="8pt" padding-bottom="2pt" space-after="2pt" margin-left="-10mm">
                            <fo:inline font-style="italic">Table <xsl:value-of select="$tCount"/>
                                <xsl:value-of select="concat(' - ', ./title)"/></fo:inline>
                            <fo:retrieve-table-marker retrieve-class-name="tab-cont" 
                                retrieve-position-within-table="first-starting" 
                                retrieve-boundary-within-table="table"/>
                        </fo:block>
                    </xsl:if>
                    <xsl:if test="not(title/text())">
                        <fo:block keep-with-next="always" text-align="center" space-after="2pt">
                            <fo:inline font-style="italic">Table <xsl:value-of select="$tCount"/>
                            </fo:inline>
                            <fo:retrieve-table-marker retrieve-class-name="tab-cont" 
                                retrieve-position-within-table="first-starting" 
                                retrieve-boundary-within-table="table"/>
                        </fo:block>
                    </xsl:if>
                </fo:table-cell>
            </fo:table-row>
        </fo:table-header>
        <fo:table-body>
            <fo:table-row>
                <fo:table-cell>
                    <fo:marker marker-class-name="tab-cont"/>
                    <fo:block/>
                </fo:table-cell>
            </fo:table-row>
            <fo:table-row>
                <fo:table-cell>
                    <fo:marker marker-class-name="tab-cont">&#x00A0;- (Continued)</fo:marker>
                    <fo:block keep-with-previous="always">
                        <fo:marker marker-class-name="tab-cont">&#x00A0;- (Continued)</fo:marker>
                        <fo:table table-layout="fixed" width="100%">
                            <xsl:for-each select="colspec">
                                <fo:table-column column-width="proportional-column-width(@colwidth)"/>
                            </xsl:for-each>
                            <fo:table-header>
                                <xsl:for-each select="./tgroup/thead/row">
                                    <fo:table-row>
                                        <xsl:apply-templates/>
                                    </fo:table-row>
                                </xsl:for-each>
                            </fo:table-header>
                            <fo:table-footer>
                                <fo:table-row>
                                    <xsl:for-each select="./tgroup/thead/row[1]/entry"><!--[position() &gt; 1]-->
                                        <fo:table-cell border-top-style="solid" border-top-color="black" border-collapse="collapse">
                                            <fo:block/>
                                        </fo:table-cell>
                                    </xsl:for-each>
                                </fo:table-row>
                            </fo:table-footer>
                            <fo:table-body>
                                <xsl:for-each select="./tgroup/tbody/row">
                                    <fo:table-row>
                                        <xsl:apply-templates/>
                                    </fo:table-row>
                                </xsl:for-each>
                                <xsl:if test="./tgroup/tfoot">
                                    <xsl:for-each select="./tgroup/tfoot/row">
                                        <fo:table-row>
                                            <xsl:apply-templates/>
                                        </fo:table-row>
                                    </xsl:for-each>
                                </xsl:if>
                            </fo:table-body>
                        </fo:table>
                    </fo:block>
                </fo:table-cell>
            </fo:table-row>
        </fo:table-body>
    </fo:table>
</xsl:template>

1 个答案:

答案 0 :(得分:1)

这是因为levelledPara/tabletable[parent::levelledPara]table[not(parent::proceduralStep)]都匹配。你可能想写:

<xsl:template match="table[not(parent::levelledPara or parent::proceduralStep)]">

而不是:

<xsl:template match="table[not(parent::levelledPara)] | table[not(parent::proceduralStep)]">
  

这只是因为我在匹配语句中使用了两个“或”   不同的父标签(levelledPara和proceduralStep)?

但你没有or。你有union运营商。你正在加工桌子,而不是他们的父母。这也会奏效:

<xsl:template match="table[not(parent::levelledPara | parent::proceduralStep)]">