xslt apply-templates忽略一个子类型

时间:2014-07-28 07:37:34

标签: xslt xslt-2.0

我在XSLT中使用了以下XML。

 <section level="sect4" number-type="manual" num="(ii)">
        <title>
            Non-Hong Kong companies
            <footnote num="123">
                <para>The venerable statutory .</para>
            </footnote> with a place of business in Hong Kong
            <footnote num="124">
                <para>It may be noted in this context of English judgments.</para>
            </footnote>
        </title>
        <para>
            <phrase>3.039</phrase> Companies incorporal Companies,
            <footnote num="125">
                <para>Registration of the information specified in this
                 section must be effected</para>
            </footnote>
            of which three are relevant for present purposes:
        </para>
    </section>

这里我想申请模板但忽略脚注,当我使用下面的内容时。

    <xsl:template name="IndexItem">
    <xsl:if test="not(contains(@level,'sect1'))"><!--changed fron @num to sect2-->
        <xsl:variable name="tocpg">
            <xsl:value-of select="concat('#P',descendant::phrase[1])"/>
        </xsl:variable>
        <xsl:variable name="nu">
        <xsl:number format="(i)"/>
        </xsl:variable>
        <xsl:variable name="tocpgtag" select="translate($tocpg,'.', '-')"/>
        <xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'"/>
        <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
        <xsl:variable name="text" select="current()/title/text()"/>
        <xsl:variable name="Brac">
            <xsl:choose>
                <xsl:when test="contains(current()/@num,$nu)">
                    <xsl:value-of select="3"/>
                </xsl:when>
                <xsl:when test="contains(current()/@num,'(')">
                    <xsl:value-of select="2"/>
                </xsl:when>
                <xsl:otherwise>
                                    <xsl:value-of select="1"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <xsl:variable name="d">
        <xsl:value-of select="concat('toc-item-',$ThisDocument//ntw:nums[@num=$Brac]/@word,'-level')"/>
</xsl:variable>
        <table class="{$d}">
            <tbody>
                <tr>
                    <td class="toc-item-num">
                        <xsl:value-of select="@num"/>
                    </td>
                    <td class="toc-title">
                     <xsl:apply-templates select="node() except child::footnote"/>
                    </td>
                    <td class="toc-pg">
                        <a href="{$tocpgtag}">
                            <xsl:value-of select="descendant::phrase[1]"/><![CDATA[ ]]>
                        </a>
                    </td>
                </tr>
            </tbody>
        </table>
        </xsl:if>
    </xsl:template>

输出

Non-Hong Kong companies <sup>123</sup>  with a place of business in Hong Kong <sup>124</sup>

当我使用这个

<xsl:apply-templates select="./title[not(./footnote)]"/>

它没有显示任何内容,预期的输出是,只是

Non-Hong Kong companies with a place of business in Hong Kong

并且如果还有其他孩子(如内容样式),则应该应用它们,只有footnote被忽略。

请让我知道我该怎么做。

由于

1 个答案:

答案 0 :(得分:0)

您可以尝试except运算符:

<xsl:template match="title">
    <xsl:apply-templates select="node() except child::footnote"/>
</xsl:template>

修改

我推断您是从section节点调用此模板。试试这个:

<xsl:apply-templates select="title/node() except descendant::footnote"/>