从xsl:number中排除具有特定属性值的元素

时间:2017-04-26 18:11:39

标签: xml xslt xsl-fo

我使用<xsl:number>来计算<proceduralStep>。 (我使用Antenna House 6.2)

<xsl:number count="proceduralStep" from="content" level="multiple" format="1.1.1.1.1"/>

但我想要排除任何具有属性@changeType='delete'的父级或子级的proceduralStep

XML可能看起来像这些:

    <proceduralStep><para>Install This.</para></proceduralStep>
    <proceduralStep><para changeMark="1" changeType="delete">Delete this line.</para></proceduralStep>
    <proceduralStep><para>Continue with ths</para></proceduralStep>

    <proceduralStep><para><changeInline  changeMark="1" changeType="delete">And this line.</changeInline></para></proceduralStep>

    <proceduralStep><para>Continue with this</para></proceduralStep>
<revst changeMark="1" >
    <proceduralStep><para>Turn the screw....</para></proceduralStep>
    <proceduralStep><para>Hold assembly tool....</para></proceduralStep>
    </revst>

输出应该如下所示

    1.2.11 Install This
           Delete this line
    1.2.12 Continue with ths

另一个问题是当使用<revst>作为<proceduralStep>的包装时,编号会重新启动:

    1.2.13 Continue with this
    1.2.1 Turn the screw....
    1.2.2 Hold assembly tool...

而不是:

    1.2.13 Continue with this
    1.2.14 Turn the screw....
    1.2.15 Hold assembly tool...

<xsl:number count="ancestor-or-self::*[changeType!='delete']" from="content" level="multiple" format="1.1.1.1.1"/>

抛出错误:只有孩子&#39;和&#39;属性&#39;在谓词外的匹配模式中允许使用轴

1 个答案:

答案 0 :(得分:1)

  

但我想排除任何有父母或子女的proceduralStep   属性@changeType='delete'

要计算具有属性proceduralStep的子节点的@changeType='delete',请使用:

count="proceduralStep[not(*/@changeType = 'delete')]"

要将此扩展到父节点,您可以使用:

count="proceduralStep[not(*/@changeType = 'delete' or parent::*/@changeType = 'delete')]"

请注意,a!=bnot(a=b)不同。