父子节点和父节点的总和

时间:2013-06-10 10:27:46

标签: xslt

我想要对我的xslt进行一些小改动,如下所示。

 <xsl:variable name="sectnum">
    <xsl:number level="any" count="section[(@num and @level ='sect2') or (@level !='sect2' and @level !='sect1') or @level='sect2' or contains(//content-style,'Part')]"/>
        </xsl:variable>

这里实际上我有para作为section / para的路径,而para我有para / content-style。  我想用包含'Part'的字符串计算para。请让我知道我该怎么做。上面的变量只给出了@level属性的计数,但没有为para部分给出计数。

我的xml的一部分如下。

  <?xml version="1.0" encoding="UTF-8"?>
<chapter>
<section level="sect2" number-type="manual" num="1.">
            <title>INTRODUCTION</title>
            <para>
                <phrase>1.001</phrase> This part will consider matters relevant to the administration of a deceased's estate from the death to the application for the grant. Chapter 1 will outline some preliminary steps to be taken immediately on obtaining instructions to act. The distinction between testate and intestate succession, and the practical implications of each, will be considered in Chapter 2. Foreign elements, particularly the relevant questions of domicile, the involvement of PRC law, and overseas property, will be noted in Chapter 3. The steps necessary to obtain estate duty clearance (where now necessary) will be briefly considered in Chapter 4. </para>
                </section>
                <section level="sect2">
                    <para>
                    <content-style font-style="bold">Part 1 The deceased person</content-style>
                </para>
                </section>
                </chapter>

第二个场景

    <chapter><section level="sect2">
    <para>
                        <content-style font-style="bold">Part 5 The dependants</content-style>
                    </para></section>
<section level="sect2">
                    <para>Complete the table at Appendix B. </para>
                    <para>
                        <content-style font-style="bold">Part 6 The estate</content-style>
                    </para></section>
    </chapter>

由于

1 个答案:

答案 0 :(得分:0)

查看当前变量,除非您有拼写错误,否则实际上可以简化为以下

<xsl:number level="any" count="section[@level !='sect1' or contains(//content-style,'Part')]"/>

但是,我认为您对包含的问题之一。因为xpath表达式以//开头,这意味着它相对于顶级文档元素而不是当前节点,因此只检查第一个内容样式元素发现。

此外,如果您只想使用元素计算元素,其中内容样式包含“部分”,那么您必须像这样扩展它

"... or contains(.//content-style,'Part')] or para[not(.//content-style)]"

注意包含开头的句号,表明它是相对于当前节点的。

尝试其中任何一种

<xsl:number level="any" 
     count="section[
        (@num and @level ='sect2') 
        or (@level !='sect2' and @level !='sect1') 
        or @level='sect2' 
        or para[not(.//content-style)] 
        or contains(.//content-style,'Part')]"/>

或者

<xsl:number level="any" 
     count="section[
         @level !='sect1' 
         or para[not(.//content-style)]  
         or contains(.//content-style,'Part')]"/>

请注意包含开头的句号,表示它相对于当前节点。