0

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>

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.

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>

second Scenario

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

Thanks

user2423959
  • 836
  • 1
  • 13
  • 27
  • It would be really be helpful if you add a input example. Would you only count section with different conditions? – hr_117 Jun 10 '13 at 10:52
  • Hi @hr_117 here the count is based on section conditions. and also the count should be done for second section as it has 'part' in the para(Part 1 The deceased person). Thanks – user2423959 Jun 10 '13 at 11:31
  • Your new example doesn't contain any **section** elements. Are you counting **section** elements or **para** elements? It would help if you showed your expected output in both cases. Thanks! – Tim C Jun 10 '13 at 14:26
  • @TimC sorry for giving invalid input. now i have updated my question. sorry again. Thanks – user2423959 Jun 10 '13 at 14:35

1 Answers1

0

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

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.

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

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

Try either of these instead

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

Or

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

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

Tim C
  • 70,053
  • 14
  • 74
  • 93
  • Hi @Tim C this worked good, but there is also an exception, it should not count if it is like the follows Part 1 The deceased person. i.e. if the content-style is inside the text. please let me know how do i do it. Thanks again – user2423959 Jun 10 '13 at 13:11
  • when i add this to my variable the section number is getting repeated when i add this to my data in my updated question(second scenario) it is giving sec-01, sec-01, but i want it to be sec-01 and sec-02. please help me to solve this issue. Thanks. – user2423959 Jun 10 '13 at 13:58
  • Hmmm... That is odd, as get the numbering as 1, 2. I am not sure what I missing, I am afraid. – Tim C Jun 10 '13 at 21:10
  • @user2423959: The solution form Tim C works fine for me. I fear to help you more we need a new question. With a small complete not working example (xml and xlst) – hr_117 Jun 17 '13 at 11:59
  • Hi @hr_117 but there is a repetition of number when i try it, i use altova xml spy. else can you please provide me your email address so that i can email you the code, 'coz i can't enter my entire code here in this page – user2423959 Jun 17 '13 at 12:09
  • Sorry but, no. Please try to create a small xml and xslt which shows your problem. – hr_117 Jun 17 '13 at 12:22