xsl counter with and condition

2019-08-23 02:27发布

i've a condition where the section element should be having both a num attribute and level can be any apart from level 2. like below.

<section level="sect2" num="1.">
    <title>Flowchart&#x2014;HKIAC Mediation</title>
</section>  

 <section level="sect3">
    <title>Flowchart&#x2014;HKIAC Mediation</title>
</section>

<section level="sect2">
    <title>Flowchart&#x2014;HKIAC Mediation</title>
</section>

and when i use the below xslt it is counting only the first xml with number attribute and leaving second and third. but i want to count both first and third leaving second.

i've used the below statement

<xsl:number count='section[@num]'/>

but i want something similar to below

<xsl:number count='section[@num] and section[@level!='sect2']'/>

Thanks

标签: xslt
2条回答
forever°为你锁心
2楼-- · 2019-08-23 03:04

In my understanding its more:

<xsl:number count="section[@num or @level != 'sect2']"/> 

Because: but i want to count both first and third leaving second. EDIT: Seems it should be fist and second What seems to be all section with "@level != 'sect2'" and all section with "@num".

查看更多
乱世女痞
3楼-- · 2019-08-23 03:10

Try this -

<xsl:number count="section[@num and @level != 'sect2']"/>

For your issue in the comment try this which means num attribute not present -

<xsl:number count="section[not(@num) and @level = 'sect2']"/>

You mean you do not care if the level=sect2 then just remove that like this -

<xsl:number count="section[not(@num)]"/>

This will give you count where num attribute is not present and value of level is not sect2.

<xsl:number count="section[not(@num) and @level != 'sect2']"/>
查看更多
登录 后发表回答