0

以下のように 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>

ここでは、実際にはセクション/パラとしてパラのパスがあり、パラにはパラ/コンテンツスタイルがあります。「Part」を含む文字列でパラを数えたいです。どうすればいいのか教えてください。上記の変数は @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>

2 番目のシナリオ

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

ありがとう

4

1 に答える 1

0

現在の変数を見ると、タイプミスがない限り、実際には次のように簡略化できます

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

ただし、 containsに関する問題の 1 つだと思います。xpath 式は で始まるため//、現在のノードではなく最上位のドキュメント要素に相対的であることを意味し、最初に見つかったcontent-style要素のみをチェックします。

また、コンテンツ スタイルに「Part」が含まれるpara要素を持つsection要素のみをカウントする場合は、そのように拡張する必要があります。

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

現在のノードに相対的であることを示すために、contains の先頭にあるピリオドに注意してください。

代わりにこれらのいずれかを試してください

<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')]"/>

現在のノードに相対的であることを示すために、 containsの先頭にあるピリオドに注意してください。

于 2013-06-10T12:48:10.700 に答える