父子节点和父节点的总和 [英] sum of parent child and parent nodes

查看:35
本文介绍了父子节点和父节点的总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对我的 xslt 做一个小改动,如下所示.

i want a small change in my xslt which is as below.

 <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 部分提供计数.

here actually i have path for para as section/para and in para i have para/content-style. i want to count the para with string containing 'Part' in it. please let me know how do i do it. the above variable is giving count only for the @level attributes but not for the para part.

我的 xml 的一部分如下.

a part of my xml is as below.

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

谢谢

推荐答案

看你当前的变量,除非你有错别字,其实可以简化成下面这样

Looking at your current variable, unless you have a typo, it can actually be simplified to the following

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

但是,我认为您遇到的问题之一包含.因为您的 xpath 表达式以 // 开头,这意味着它相对于顶级文档元素,而不是当前节点,因此只会检查第一个 content-style 它找到的元素.

However, what I think one of the problems you have with the contains. Because you xpath expression starts with //, this means it is relative to the top-level document element, and not the current node, and so will only check the first content-style element it finds.

此外,如果您只想用 para 元素计算 section 元素,其中 content-style 包含Part",那么您必须像这样扩展它

Also, if you only wanted to count section elements with a para element where the content-style contains "Part", then you have to extend it like so

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

注意 contains 开头的句号表示它是相对于当前节点的.

Note the full-stop at the start of the contains to indicate it is relative to the current node.

尝试其中任何一个

<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 开头的句号表示它是相对于当前节点的.

Note the full-stop at the start of the contains to indicate it is relative to the current node.

这篇关于父子节点和父节点的总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆